Providing window updates from a computer to a network interface device

ABSTRACT

An intelligent network interface card (INIC) or communication processing device (CPD) works with a host computer for data communication. The device provides a fast-path that avoids protocol processing for most messages, greatly accelerating data transfer and offloading time-intensive processing tasks from the host CPU. The host retains a fallback processing capability for messages that do not fit fast-path criteria, with the device providing assistance such as validation even for slow-path messages, and messages being selected for either fast-path or slow-path processing. A context for a connection is defined that allows the device to move data, free of headers, directly to or from a destination or source in the host. The context can be passed back to the host for message processing by the host. The device contains specialized hardware circuits that are much faster at their specific tasks than a general purpose CPU. When the context is held by the INIC, the INIC can advertise a receive window of memory space at the destination that corresponds to the context and is available to store data.

CROSS REFERENCE TO RELATED APPLICATIONS

[0001] This application claims the benefit under 35 U.S.C. §120 of U.S.patent application Ser. No. 10/277,604, filed Oct. 18, 2002, which inturn claims the benefit under 35 U.S.C. §120 of U.S. patent applicationSer. No. 10/005,536, filed Nov. 7, 2001, which in turn claims thebenefit under 35 U.S.C. §120 of U.S. patent application Ser. No.09/384,792, filed Aug. 27, 1999, now U.S. Pat. No. 6,434,620, which inturn: 1) claims the benefit under 35 U.S.C. §119 of provisional patentapplication serial No. 60/098,296, filed Aug. 27, 1998, 2) claims thebenefit under 35 U.S.C. §120 of U.S. patent application Ser. No.09/067,544, filed Apr. 27, 1998, now U.S. Pat. No. 6,226,680, and 3)claims the benefit under 35 U.S.C. §120 of U.S. patent application Ser.No. 09/141,713, filed Aug. 28, 1998, now U.S. Pat. No. 6,389,479. U.S.Pat. No. 6,226,680 in turn claims the benefit under 35 U.S.C. §119 ofprovisional patent application serial No. 60/061,809 filed Oct. 14,1997. The present application also claims the benefit under 35 U.S.C.§120 of U.S. patent application Ser. No. 09/464,283, filed Dec. 15,1999, now U.S. Pat. No. 6,427,173, and claims the benefit under 35U.S.C. §120 of U.S. patent application Ser. No. 09/514,425, filed Feb.28, 2000, now U.S. Pat. No. 6,427,171. All of the above-listedapplications are incorporated by reference herein.

[0002] Cross Reference to Compact Disc Appendix

[0003] The Compact Disc, which is a part of the present disclosure,includes a recordable Compact Disc (CD-R) containing information(including CD Appendices A, B, C and D) that is part of the disclosureof the present patent document. A portion of the disclosure of thispatent document contains material that is subject to copyrightprotection. All the material on the Compact Disc is hereby expresslyincorporated by reference into the present application. The copyrightowner of that material has no objection to the facsimile reproduction byanyone of the patent document or the patent disclosure, as it appears inthe Patent and Trademark Office patent files or records, but otherwisereserves all copyright rights.

BACKGROUND OF THE INVENTION

[0004] Network processing as it exists today is a costly and inefficientuse of system resources. A 200 MHz Pentium-Pro is typically consumedsimply processing network data from a 100 Mb/second-network connection.The reasons that this processing is so costly are described in the nextfew pages.

[0005] When network packet arrives at a typical network interface card(NIC), the NIC moves the data into pre-allocated network buffers insystem main memory. From there the data is read into the CPU cache sothat it can be checksummed (assuming of course that the protocol in userequires checksums. Some, like IPX, do not.). Once the data has beenfully processed by the protocol stack, it can then be moved into itsfinal destination in memory. Since the CPU is moving the data, and mustread the destination cache line in before it can fill it and write itback out, this involves at a minimum 2 more trips across the systemmemory bus. In short, the best one can hope for is that the data willget moved across the system memory bus 4 times before it arrives in itsfinal destination. It can, and does, get worse. If the data happens toget invalidated from system cache after it has been checksummed, then itmust get pulled back across the memory bus before it can be moved to itsfinal destination. Finally, on some systems, including Windows NT 4.0,the data gets copied yet another time while being moved up the protocolstack. In NT 4.0, this occurs between the miniport driver interface andthe protocol driver interface. This can add up to a whopping 8 tripsacross the system memory bus (the 4 trips described above, plus the moveto replenish the cache, plus 3 more to copy from the miniport to theprotocol driver). That's enough to bring even today's advanced memorybusses to their knees.

[0006] In all but the original move from the NIC to system memory, thesystem CPU is responsible for moving the data. This is particularlyexpensive because while the CPU is moving this data it can do nothingelse. While moving the data the CPU is typically stalled waiting for therelatively slow memory to satisfy its read and write requests. A CPU,which can execute an instruction every 5 nanoseconds, must now wait aslong as several hundred nanoseconds for the memory controller to respondbefore it can begin its next instruction. Even today's advancedpipelining technology doesn't help in these situations because thatrelies on the CPU being able to do useful work while it waits for thememory controller to respond. If the only thing the CPU has to lookforward to for the next several hundred instructions is more data moves,then the CPU ultimately gets reduced to the speed of the memorycontroller.

[0007] Moving all this data with the CPU slows the system down evenafter the data has been moved. Since both the source and destinationcache lines must be pulled into the CPU cache when the data is moved,more than 3 k of instructions and or data resident in the CPU cache mustbe flushed or invalidated for every 1500 byte frame. This is of courseassuming a combined instruction and data second level cache, as is thecase with the Pentium processors. After the data has been moved, theformer resident of the cache will likely need to be pulled back in,stalling the CPU even when we are not performing network processing.Ideally a system would never have to bring network frames into the CPUcache, instead reserving that precious commodity for instructions anddata that are referenced repeatedly and frequently.

[0008] But the data movement is not the only drain on the CPU. There isalso a fair amount of processing that must be done by the protocol stacksoftware. The most obvious expense is calculating the checksum for eachTCP segment (or UDP datagram). Beyond this, however, there is otherprocessing to be done as well. The TCP connection object must be locatedwhen a given TCP segment arrives, IP header checksums must becalculated, there are buffer and memory management issues, and finallythere is also the significant expense of interrupt processing, discussedbelow.

[0009] A 64 k server message block (SMB) request (write or read-reply)is typically made up of 44 TCP segments when running over Ethernet,which has a 1500 byte maximum transmission unit (MTU). Each of thesesegments may result in an interrupt to the CPU. Furthermore, since TCPmust acknowledge (ACK) all of this incoming data, it's possible to getanother 44 transmit-complete interrupts as a result of sending out theTCP acknowledgements. While this is possible, it is not terribly likely.Delayed ACK timers allow us to acknowledge more than one segment at atime. And delays in interrupt processing may mean that we are able toprocess more than one incoming network frame per interrupt.Nevertheless, even if we assume 4 incoming frames per input, and anacknowledgement for every 2 segments (as is typical per theACK-every-other-segment property of TCP), we are still left with 33interrupts per 64 k SMB request.

[0010] Interrupts tend to be very costly to the system. Often when asystem is interrupted, important information must be flushed orinvalidated from the system cache so that the interrupt routineinstructions, and needed data can be pulled into the cache. Since theCPU will return to its prior location after the interrupt, it is likelythat the information flushed from the cache will immediately need to bepulled back into the cache. What's more, interrupts force a pipelineflush in today's advanced processors. While the processor pipeline is anextremely efficient way of improving CPU performance, it can beexpensive to get going after it has been flushed. Finally, each of theseinterrupts results in expensive register accesses across the peripheralbus (PCI).

[0011] We noted earlier that when the CPU has to access system memory,it may be stalled for several hundred nanoseconds. When it has to readfrom PCI, it may be stalled for many microseconds. This happens everytime the CPU takes an interrupt from a standard NIC. The first thing theCPU must do when it receives one of these interrupts is to read the NICInterrupt Status Register (ISR) from PCI to determine the cause of theinterrupt. The most troubling thing about this is that since interruptlines are shared on PC-based systems, we may have to perform thisexpensive PCI read even when the interrupt is not meant for us.

[0012] Other peripheral bus inefficiencies also exist. Typical NICsoperate using descriptor rings. When a frame arrives, the NIC reads areceive descriptor from system memory to determine where to place thedata. Once the data has been moved to main memory, the descriptor isthen written back out to system memory with status about the receivedframe. Transmit operates in a similar fashion. The CPU must notify thatNIC that it has a new transmit. The NIC will read the descriptor tolocate the data, read the data itself, and then write the descriptorback with status about the send. Typically on transmits the NIC willthen read the next expected descriptor to see if any more data needs tobe sent. In short, each receive or transmit frame results in 3 or 4separate PCI reads or writes, not counting the status register read.

SUMMARY OF THE INVENTION

[0013] The present invention offloads network processing tasks from aCPU to a cost-effective intelligent network interface card (INIC). Anadvantage of this approach is that a vast majority of network messagedata is moved directly from the INIC into its final destination. Anotheradvantage of this approach is that the data may be moved in a singletrip across the system memory bus. The offloading allows the CPU toavoid header processing, data copying, and checksumming. Since networkmessage data does not need to be placed in a CPU cache, the CPU cachemay be free for storage of other important instructions or data.Interrupts may be reduced to four interrupts per 64 k SMB read and twointerrupts per 64 k SMB write. Other advantages include a reduction ofCPU reads over the PCI bus and fewer PCI operations per receive ortransmit transaction.

BRIEF DESCRIPTION OF THE DRAWINGS

[0014]FIG. 1 is a diagram of fast-path and slow-path modes ofcommunication processing.

[0015]FIG. 2 is a diagram of different buffers employed for thefast-path and slow-path modes of processing received messages.

[0016]FIG. 3 is a diagram of buffers employed for the fast-path andslow-path modes of transmitting messages.

[0017]FIG. 4 shows an initial format of an interrupt status register(ISR) of the present invention.

[0018]FIG. 5 shows mapping of network packets according to the presentinvention with mbufs and buffer descriptors.

[0019]FIG. 6 shows some control information structures used to representnetwork addresses and protocols according to the present invention.

[0020]FIG. 7 shows a host interface structure combining plural protocolstacks and drivers for working with an add-on INIC.

[0021]FIG. 8A shows a received TCP packet after processing by the INIC.

[0022]FIG. 8B shows a received ARP frame after processing by the INIC.

[0023]FIG. 9A shows a received data packet for a TCP fast-pathconnection.

[0024]FIG. 9B shows a received data packet for a TCP slow-pathconnection.

[0025]FIG. 9C shows a received ARP frame.

[0026]FIG. 10 shows sending a fast-path data packet.

[0027]FIG. 11 shows sending a slow-path data packet.

[0028]FIG. 12 shows sending a non-data command to the INiC.

[0029]FIG. 13 is a diagram of the INIC connected to the INIC miniportdriver over the PCI bus.

[0030]FIG. 14 is a diagram of an INIC driver connected to plural INICcards each having plural network connections.

[0031]FIG. 15 shows sending a packet containing an ATCP command buffer.

[0032]FIG. 16 shows mapping the command buffer of FIG. 15 and giving theaddress of that buffer to the INIC.

[0033]FIG. 17 shows an example of a receive header and data buffer thathave been created by the INIC.

[0034]FIG. 18 shows the mapping of header buffer and data bufferdescriptors for a received packet.

[0035]FIG. 19 is a state diagram summary of a receive finite statemachine showing the main events and transitions.

[0036]FIG. 20 is a state diagram summary of a transmit finite statemachine showing the main events and transitions.

[0037]FIG. 21 is a diagram of the INIC hardware.

[0038]FIG. 22 is a diagram of a communications microprocessor includedin the INIC, showing functions associated with a plurality ofinstruction phases.

[0039]FIG. 23A is a diagram of a first phase of the microprocessor ofFIG. 22, including the first register set and related controls.

[0040]FIG. 23B is a diagram of a second microprocessor phase, includingreading addresses and data out of a RAM file register.

[0041]FIG. 23C is a diagram of a third microprocessor phase, includingALU and queue operations.

[0042]FIG. 24 is a diagram of various sequencers contained in the INIC.

[0043]FIG. 25 is a diagram of data movement for a Pci slave write toDRAM.

[0044]FIG. 26 is a diagram of an SRAM Control Sequencer contained in theINIC.

[0045]FIG. 27 is a timing diagram for the SRAM Control Sequencer.

[0046]FIG. 28 is a block diagram of an External Memory Control.

[0047]FIG. 29 is a timing diagram illustrating a data read from SDRAM.

[0048]FIG. 30 is a block diagram of an External Memory Read Sequencer.

[0049]FIG. 31 is a timing diagram illustrating a data write to SDRAM.

[0050]FIG. 32 is a diagram of an External Memory Write Sequencer.

[0051]FIG. 33 is a diagram of a PCI Master-Out Sequencer.

[0052]FIG. 34 is a diagram of a PCI Master-In Sequencer.

[0053]FIG. 35 is a diagram illustrating data movement from DRAM to Pcitarget.

[0054]FIG. 36 is a diagram of a DRAM to PCI Sequencer.

[0055]FIG. 37 is a diagram illustrating data movement from a PCI targetto DRAM.

[0056]FIG. 38 is a diagram of a PCI to DRAM Sequencer.

[0057]FIG. 39 is a diagram illustrating data movement from SRAM to Pcitarget.

[0058]FIG. 40 is a diagram of a SRAM to PCI Sequencer.

[0059]FIG. 41 is a diagram illustrating data movement from a Pci targetto DRAM.

[0060]FIG. 42 is a diagram of a PCI to SRAM Sequencer.

[0061]FIG. 43 is a diagram illustrating data movement from DRAM to SRAM.

[0062]FIG. 44 is a diagram of a DRAM to SRAM Sequencer.

[0063]FIG. 45 is a diagram illustrating data movement from SRAM to DRAM.

[0064]FIG. 46 is a diagram of a SRAM to DRAM Sequencer.

[0065]FIG. 47 is a diagram of a sequence of events when a PCI SlaveInput Sequencer is the target of a Pci write operation.

[0066]FIG. 48 is a diagram of a sequence of events when a PCI SlaveOutput Sequencer is the target of a Pci read operation.

[0067]FIG. 49 is a diagram of a sequence of events for reception of apacket.

[0068]FIG. 50 is a diagram of a Frame Receive Sequencer.

[0069]FIG. 51 is a diagram of a sequence of events for transmission of apacket.

[0070]FIG. 52 is a diagram of a Frame Transmit Sequencer.

[0071]FIG. 53 is a timing diagram for a Queue Manager.

[0072]FIG. 54 is a diagram of the Queue Manager.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

[0073] In order to keep the system CPU from having to process the packetheaders or checksum the packet, this task is performed on the INIC,which presents a challenge. There are more than 20,000 lines of C codethat make up the FreeBSD TCP/IP protocol stack, for example. This ismore code than could be efficiently handled by a competitively pricednetwork card. Further, as noted above, the TCP/IP protocol stack iscomplicated enough to consume a 200 MHz Pentium-Pro. In order to performthis function on an inexpensive card, special network processinghardware has been developed instead of simply using a general purposeCPU.

[0074] In order to operate this specialized network processing hardwarein conjunction with the CPU, we create and maintain what is termed acontext. The context keeps track of information that spans many,possibly discontiguous, pieces of information. When processing TCP/IPdata, there are actually two contexts that must be maintained. The firstcontext is required to reassemble IP fragments. It holds informationabout the status of the IP reassembly as well as any checksuminformation being calculated across the IP datagram (UDP or TCP). Thiscontext is identified by the IP_ID of the datagram as well as the sourceand destination IP addresses. The second context is required to handlethe sliding window protocol of TCP. It holds information about whichsegments have been sent or received, and which segments have beenacknowledged, and is identified by the IP source and destinationaddresses and TCP source and destination ports.

[0075] If we were to choose to handle both contexts in hardware, wewould have to potentially keep track of many pieces of information. Onesuch example is a case in which a single 64 k SMB write is broken downinto 44 1500 byte TCP segments, which are in turn broken down into 131576 byte IP fragments, all of which can come in any order (though themaximum window size is likely to restrict the number of outstandingsegments considerably).

[0076] Fortunately, TCP performs a Maximum Segment Size negotiation atconnection establishment time, which should prevent IP fragmentation innearly all TCP connections. The only time that we should end up withfragmented TCP connections is when there is a router in the middle of aconnection which must fragment the segments to support a smaller MTU.The only networks that use a smaller MTU than Ethernet are serial lineinterfaces such as SLIP and PPP. At the moment, the fastest of theseconnections only run at 128 k (ISDN) so even if we had 256 of theseconnections, we would still only need to support 34 Mb/sec, or a littleover three 10bT connections worth of data. This is not enough to justifyany performance enhancements that the INIC offers. If this becomes anissue at some point, we may decide to implement the MTU discoveryalgorithm, which should prevent TCP fragmentation on all connections(unless an ICMP redirect changes the connection route while theconnection is established). With this in mind, it seems a worthysacrifice to not attempt to handle fragmented TCP segments on the INIC.

[0077] SPX follows a similar framework as TCP, and so the expansion ofthe INIC to handle IPX/SPX messages is straightforward. UDP, on theother hand, does not support the notion of a Maximum Segment Size, so itis the responsibility of IP to break down a UDP datagram into MTU sizedpackets. Thus, fragmented UDP datagrams are very common. The most commonUDP application running today is NFSV2 over UDP. While this is also themost common version of NFS running today, the current version of Solarisbeing sold by Sun Microsystems runs NFSV3 over TCP by default. A firstembodiment described in detail in this document offers networkprocessing assistance to non-fragmented TCP connections on the INIC,while extension of this design to process other message protocols, suchas SPX/IPX is straightforward.

[0078] As noted above, fragmented TCP segments are not fully processedby the initial INIC configuration. We have also opted to not have theINIC handle TCP connection and breakdown. Other TCP “exceptions” whichwe have elected to not handle on the INIC include: 1) RetransmissionTimeout—Occurs when we do not get an acknowledgement for previously sentdata within the expected time period; 2) Out of order segments—Occurswhen we receive a segment with a sequence number other than the nextexpected sequence number; 3) FIN segment—Signals the close of theconnection.

[0079] Since we have now eliminated support for so many different codepaths, it might seem hardly worth the trouble to provide any assistanceby the INIC at all. This is not the case. According to W. RichardStevens and Gary Write in Volume 2 of their book “TCP/IP Illustrated”,which along with Volume 1 is incorporated by reference herein, TCPoperates without experiencing any exceptions between 97 and 100 percentof the time in local area networks. As network, router, and switchreliability improve this number is likely to only improve with time.

[0080] As shown in FIG. 1, different modes of operation are employeddepending upon whether a given network packet fits our criteria forprocessing by an INIC 50 or a host 52. The INIC 50 has a physical layer55 connected by a PCI bus 57 to a physical layer 59 of the host 52. TheINIC 50 has media access (MAC) 63, IP 64, TCP 65 and netbios 66 hardwareprocessing layers, while the host 52 has media access (MAC) 73, IP 74,TCP 75, and TDI 76 hardware processing layers, which operate on behalfof a client 77. In a first mode, termed fast-path 80, network frames areprocessed on the INIC 50 through TCP. In a second mode, termed slow-path82, the network frames are processed through the card and the cardoperates like a conventional NIC. In the slow-path case, network framesare handed to the system at the MAC layer and passed up through the hostprotocol stack like any other network frame. In the fast-path case,network data is given to the host after the headers have been processedand stripped.

[0081] The transmit case works in much the same fashion. In slow-pathmode the packets are given to the INIC with all of the headers attached.The INIC simply sends these packets out as if it were a dumb NIC. Infast-path mode, the host gives raw data to the INIC which it must carveinto MSS sized segments, add headers to the data, perform checksums onthe segment, and then send it out on the wire.

[0082] Occasionally situations arise for which a TCP connection beinghandled by the INIC needs to be returned to the host for processing. Toaccomplish this transfer of responsibility for handling a connection wecreate a communication control block (CCB). A CCB is a structure thatcontains the entire context associated with a connection. This includesthe source and destination IP addresses and source and destination TCPports that define the connection. It also contains information about theconnection itself such as the current send and receive sequence numbers,and the first-hop MAC address, etc. The complete set of CCBs exists inhost memory, but a subset of these may be “owned” by the card at anygiven time. This subset is the CCB cache. The INIC can own (cache) up to256 CCBs at any given time.

[0083] CCBs are initialized by the host during TCP connection setup.Once the connection has achieved a “steady-state” of operation, itsassociated CCB can then be turned over to the INIC, putting theconnection into fast-path mode. From this point on, the INIC owns theconnection until either a FIN arrives signaling that the connection isbeing closed, or until an exception occurs which the INIC is notdesigned to handle (such as an out of order segment). When any of theseconditions occur, the INIC will then flush the CCB back to host memory,and issue a message to the host telling it that it has relinquishedcontrol of the connection, thus putting the connection back intoslow-path mode. From this point on, the INIC simply hands incomingsegments that are destined for this CCB off to the host with all of theheaders intact.

[0084] Note that when a connection is owned by the INIC, the host is notallowed to reference the corresponding CCB in host memory as it willcontain invalid information about the state of the connection.

[0085] When a frame is received by the INIC, it must verify itcompletely before it even determines whether it belongs to one of itsCCBs or not. This includes all header validation (is it IP, IPV4 or V6,is the IP header checksum correct, is the TCP checksum correct, etc).Once this is done it must compare the source and destination IP addressand the source and destination TCP port with those in each of its CCBsto determine if it is associated with one of its CCBs. This is anexpensive process. To expedite this, we have added several features inhardware to assist us. The header is fully parsed by hardware and itstype is summarized in a single status word. The checksum is alsoverified automatically in hardware, and a hash key is created out of theIP addresses and TCP ports to expedite CCB lookup. For full details onthese and other hardware optimizations, refer to the INIC hardwarespecification sections below.

[0086] With the aid of these and other hardware features, much of thework associated with TCP is done essentially for free. Since the cardwill automatically calculate the checksum for TCP segments, we can passthis on to the host, even when the segment is for a CCB that the INICdoes not own.

[0087] By moving TCP processing down to the INIC we have offloaded thehost of a large amount of work. The host no longer has to pull the datainto its cache to calculate the TCP checksum. It does not have toprocess the packet headers, and it does not have to generate TCP ACKs.We have achieved most of the goals outlined above, but we are not doneyet.

[0088] The following paragraphs define the INIC's relation to the host'stransport layer interface, called TDI or Transport Driver Interface inWindows NT, which is described in detail further below with regard tothe Alacritech TCP (ATCP) driver.

[0089] Simply implementing TCP on the INIC does not allow us to achieveour goal of landing the data in its final destination. Somehow the hosthas to tell the INIC where to put the data. This is a problem in thatthe host can not do this without knowing what the data actually is.Fortunately, NT has provided a mechanism by which a transport driver can“indicate” a small amount of data to a client above it while telling itthat it has more data to come. The client, having then received enoughof the data to know what it is, is then responsible for allocating ablock of memory and passing the memory address or addresses back down tothe transport driver, which is in turn responsible for moving the datainto the provided location.

[0090] We will make use of this feature by providing a small amount ofany received data to the host, with a notification that we have moredata pending. When this small amount of data is passed up to the client,and it returns with the address in which to put the remainder of thedata, our host transport driver will pass that address to the INIC whichwill send the remainder of the data into its final destination viadirect memory access (DMA).

[0091] Clearly there are circumstances in which this does not makesense. When a small amount of data (500 bytes for example), with a pushflag set indicating that the data must be delivered to the clientimmediately, it does not make sense to deliver some of the data directlywhile waiting for the list of addresses to DMA the rest. Under thesecircumstances, it makes more sense to deliver the 500 bytes directly tothe host, and allow the host to copy it into its final destination.While various ranges are feasible, it is currently preferred thatanything less than a segment's (1500 bytes) worth of data will bedelivered directly to the host, while anything more will be delivered asa small piece (which may be 128 bytes), while waiting until receivingthe destination memory address before moving the rest.

[0092] The trick then is knowing when the data should be delivered tothe client or not. As we've noted, a push flag indicates that the datashould be delivered to the client immediately, but this alone is notsufficient. Fortunately, in the case of NetBIOS transactions (such asSMB), we are explicitly told the length of the session message in theNetBIOS header itself. With this we can simply indicate a small amountof data to the host immediately upon receiving the first segment. Theclient will then allocate enough memory for the entire NetBIOStransaction, which we can then use to DMA the remainder of the data intoas it arrives. In the case of a large (56 k for example) NetBIOS sessionmessage, all but the first couple hundred bytes will be DMA'd to theirfinal destination in memory.

[0093] But what about applications that do not reside above NetBIOS? Inthis case we can not rely on a session level protocol to tell us thelength of the transaction. Under these circumstances we will buffer thedata as it arrives until, 1) we have received some predetermined numberof bytes such as 8 k, or 2) some predetermined period of time passesbetween segments, or 3) we get a push flag. If after any of theseconditions occur we will then indicate some or all of the data to thehost depending on the amount of data buffered. If the data buffered isgreater than about 1500 bytes we must then also wait for the memoryaddress to be returned from the host so that we may then DMA theremainder of the data.

[0094] The transmit case is much simpler. In this case the client(NetBIOS for example) issues a TDI Send with a list of memory addresseswhich contain data that it wishes to send along with the length. Thehost can then pass this list of addresses and length off to the INIC.The INIC will then pull the data from its source location in hostmemory, as it needs it, until the complete TDI request is satisfied.

[0095] Note that when we receive a large SMB transaction, for example,that there are two interactions between the INIC and the host. The firstin which the INIC indicates a small amount of the transaction to thehost, and the second in which the host provides the memory location(s)in which the INIC places the remainder of the data. This results in onlytwo interrupts from the INIC. The first when it indicates the smallamount of data and the second after it has finished filling in the hostmemory given to it. Note the drastic reduction from the interruptsgenerated by a conventional 33/64 k SMB request that was mentioned inthe background. On transmit, we actually only receive a single interruptwhen the send command that has been given to the INIC completes.

[0096] Having now established our interaction with Microsoft's TDIinterface, we have achieved our goal of landing most of our datadirectly into its final destination in host memory. We have also managedto transmit all data from its original location on host memory. Andfinally, we have reduced our interrupts to two per 64 k SMB read and oneper 64 k SMB write. The only thing that remains in our list ofobjectives is to design an efficient host (PCI) interface.

[0097] One of our primary objectives in designing the host interface ofthe INIC was to eliminate PCI reads in either direction. PCI reads areparticularly inefficient in that they completely stall the reader untilthe transaction completes. As we noted above, this could hold a CPU upfor several microseconds, a thousand times the time typically requiredto execute a single instruction. PCI writes on the other hand, areusually buffered by the memory-bus

PCI-bridge, allowing the writer to continue on with other instructions.This technique is known as “posting”.

[0098] The only PCI read that is required by many conventional NICs isthe read of the interrupt status register. This register gives the hostCPU information about what event has caused an interrupt (if any). Inthe design of our INIC we have elected to place this necessary statusregister into host memory. Thus, when an event occurs on the INIC, itwrites the status register to an agreed upon location in host memory.The corresponding driver on the host reads this local register todetermine the cause of the interrupt. The interrupt lines are held highuntil the host clears the interrupt by writing to the INIC's InterruptClear Register. Shadow registers are maintained on the INIC to ensurethat events are not lost.

[0099] Since it is imperative that our INIC operate as efficiently aspossible, we must also avoid PCI reads from the INIC. We do this bypushing our receive buffer addresses to the INIC. As mentioned at thebeginning of this section, most NICs work on a descriptor queuealgorithm in which the NIC reads a descriptor from main memory in orderto determine where to place the next frame. We will instead writereceive buffer addresses to the INIC as receive buffers are filled. Inorder to avoid having to write to the INIC for every receive frame, weinstead allow the host to pass off a pages worth (4 k) of buffers in asingle write.

[0100] In order to reduce further the number of writes to the INIC, andto reduce the amount of memory being used by the host, we support twodifferent buffer sizes. A small buffer contains roughly 200 bytes ofdata payload, as well as extra fields containing status about thereceived data bringing the total size to 256 bytes. We can thereforepass 16 of these small buffers at a time to the INIC. Large buffers are2 k in size. They are used to contain any fast or slow-path data thatdoes not fit in a small buffer. Note that when we have a large fast-pathreceive, a small buffer will be used to indicate a small piece of thedata, while the remainder of the data will be DMA'd directly intomemory. Large buffers are never passed to the host by themselves,instead they are always accompanied by a small buffer which containsstatus about the receive along with the large buffer address. Byoperating in this manner, the driver must only maintain and process thesmall buffer queue. Large buffers are returned to the host by virtue ofbeing attached to small buffers. Since large buffers are 2 k in sizethey are passed to the INIC two buffers at a time.

[0101] In addition to needing a manner by which the INIC can passincoming data to us, we also need a manner by which we can instruct theINIC to send data. Plus, when the INIC indicates a small amount of datain a large fast-path receive, we need a method of passing back theaddress or addresses in which to put the remainder of the data. Weaccomplish both of these with the use of a command buffer. Sadly, thecommand buffer is the only place in which we must violate our rule ofonly pushing data across PCI. For the command buffer, we write theaddress of command buffer to the INIC. The INIC then reads the contentsof the command buffer into its memory so that it can execute the desiredcommand. Since a command may take a relatively long time to complete, itis unlikely that command buffers will complete in order. For this reasonwe also maintain a response buffer queue. Like the small and largereceive buffers, a page worth of response buffers is passed to the INICat a time. Response buffers are only 32 bytes, so we have to replenishthe INIC's supply of them relatively infrequently. The response buffersonly purpose is to indicate the completion of the designated commandbuffer, and to pass status about the completion.

[0102] The following examples describe some of the differing data flowsthat we might see on the INIC. For the first example of a fast-pathreceive, assume a 56 k NetBIOS session message is received on the INIC.The first segment will contain the NetBIOS header, which contains thetotal NetBIOS length. A small chunk of this first segment is provided tothe host by filling in a small receive buffer, modifying the interruptstatus register on the host, and raising the appropriate interrupt line.Upon receiving the interrupt, the host will read the ISR, clear it bywriting back to the INIC's Interrupt Clear Register, and will thenprocess its small receive buffer queue looking for receive buffers to beprocessed. Upon finding the small buffer, it will indicate the smallamount of data up to the client to be processed by NetBIOS. It willalso, if necessary, replenish the receive buffer pool on the NIC bypassing off a page worth of small buffers. Meanwhile, the NetBIOS clientwill allocate a memory pool large enough to hold the entire NetBIOSmessage, and will pass this address or set of addresses down to thetransport driver. The transport driver will allocate an NIC commandbuffer, fill it in with the list of addresses, set the command type totell the INIC that this is where to put the receive data, and then passthe command off to the INIC by writing to the command register. When theINIC receives the command buffer, it will DMA the remainder of theNetBIOS data, as it is received, into the memory address or addressesdesignated by the host. Once the entire NetBIOS transaction is complete,the INIC will complete the command by writing to the response bufferwith the appropriate status and command buffer identifier.

[0103] In this example, we have two interrupts, and all but a couplehundred bytes are DMA'd directly to their final destination. On PCI wehave two interrupt status register writes, two interrupt clear registerwrites, a command register write, a command read, and a response bufferwrite. In contrast, a host having a conventional NIC would experience anestimated 30 interrupts, 30 interrupt register reads, 30 interrupt clearwrites, and 58 descriptor reads and writes. Moreover, the data may bemoved anywhere from four to eight times across the system memory bus.

[0104] For the second example, a slow-path receive, assume the INICreceives a frame that does not contain a TCP segment for one of itsCCBs. In this case the INIC simply passes the frame to the host as if itwere a dumb NIC, according to the slow-path. If the frame fits into asmall buffer (˜200 bytes or less), then it simply fills in the smallbuffer with the data and notifies the host. Otherwise it places the datain a large buffer, writes the address of the large buffer into a smallbuffer, and again notifies the host. The host, having received theinterrupt and found the completed small buffer, checks to see if thedata is contained in the small buffer, and if not, locates the largebuffer. Having found the data, the host will then pass the frameupstream to be processed by the standard protocol stack. It must alsoreplenish the INIC's small and large receive buffer pool if necessary.

[0105] With the INIC, this slow-path results in one interrupt, oneinterrupt status register write and one interrupt clear register writeas well as a possible small and or large receive buffer register write.The data will go through the normal path, although if it is TCP datathen the host will not have to perform the checksum. A conventional NIChandling this frame will cause a single interrupt, an interrupt statusregister read, an interrupt clear register write, and a descriptor readand write. The data will get processed as it would by the INIC, exceptfor a possible extra checksum. Thus the slow-path receive mode is muchlike conventional, except for hardware assists with items such as checksums.

[0106] For the third example, a fast-path send, assume that the clienthas a small amount of data to send. It will issue the TDI Send to thetransport driver which will allocate a command buffer, fill it in withthe address of the 400 byte send, and set the command to indicate thatit is a transmit. It will then pass the command off to the INIC bywriting to the command register. The INIC will then DMA the 400 bytesinto its own memory, prepare a frame with the appropriate checksums andheaders, and send the frame out on the wire. After it has received theacknowledgement it will then notify the host of the completion bywriting to a response buffer.

[0107] With the INIC, this will result in one interrupt, one interruptstatus register write, one interrupt clear register write, a commandbuffer register write a command buffer read, and a response bufferwrite. The data is DMA'd directly from the system memory.

[0108] In contrast, a standard NIC would instead generate an interrupt,an interrupt status register read, an interrupt clear register write,and a descriptor read and write. The data would get moved across thesystem bus a minimum of four times. The resulting TCP ACK of the data,however, would add yet another interrupt, another interrupt statusregister read, interrupt clear register write, a descriptor read andwrite, and yet more processing by the host protocol stack. Theseexamples illustrate the dramatic differences between fast-path networkmessage processing and conventional.

[0109] Achievements of the Alacritech INIC include not only processingnetwork data through TCP, but also providing zero-copy support for theSMP upper-layer protocol. It accomplishes this in part by supporting twopaths for sending and receiving data, a fast-path and a slow-path. Thefast-path data flow corresponds to connections that are maintained onthe INIC, while slow-path traffic corresponds to network data for whichthe INIC does not have a connection. The fast-path flow includes passinga header to the host and subsequently holding further data for thatconnection on the card until the host responds via an INIC command witha set of buffers into which to place the accumulated data. In theslow-path data flow, the INIC will be operating as a “dumb” NIC, so thatthese packets are simply dumped into frame buffers on the host as theyarrive.

[0110] In order to support both fast and slow paths, a novel hostinterface strategy is employed. Note that with the INIC we have somechallenges that are not found with conventional NIC designs. A typicalNIC has a transmit and a receive ring of buffer descriptors. When theNIC receives a frame, it grabs a descriptor off of the receive queue, ifone is available, locates a buffer address specified within the receivedescriptor, and moves the receive frame to that address. After the datahas been moved, the descriptor is updated with status indicating that aframe has been received, and the driver is notified via a write tointerrupt status register followed by an interrupt. In this environment,the driver will typically replace the now filled-in buffer on thereceive queue, with a new free buffer.

[0111] Similarly, in a typical NIC, when the driver wishes to send aframe, it fills in a descriptor on the transmit queue with the addressand length of data to be transmitted and writes to a register on the NICtelling it that there is at least one pending transmit. The NICde-queues the now valid transmit descriptor, locates the data addressand length, and sends the frame out on the wire. Upon completion it willnotify the driver (via an ISR/interrupt) that the frame has been sent,at which point the driver can free the memory containing the send frame.

[0112] Our first challenge comes from the fact that in our design,transmits can complete out of order. For example, since our cardoffloads TCP processing from the host CPU, it is capable of transmittinga 64 k SMB write in a single command. On the INIC itself, this 64 ktransmit is broken down into many ethernet frames in accordance with theTCP maximum segment size (MSS). Because the TCP window size is typicallyabout 8 k, we can not send the 64 k in a single block of frames. Insteadthe INIC will have to go through many TCP send/acknowledgment phasesbefore the entire 64 k has been sent. While this is going on, the hostmay also issue a command to send 256 bytes. This, of course, willcomplete much sooner than the 64 k send request. These out-of-order sendcompletions will not work with the typical transmit queue design becausethere is no way for the driver to know which resources it can free whenit gets a transmit completion interrupt. To resolve this we introduce acommand/response handshake between the driver and the INIC. The drivermaintains a queue of response buffers. When it wishes to send data itfills in a command (like a transmit descriptor) and writes the physicaladdress of the command to the INIC. It also sends a handle to the INIC.When the INIC completes the request, it writes the handle back to theresponse queue of the driver. The driver uses this handle to locate theoriginal command buffer so it can free the send resources.

[0113] For receiving messages we have abandoned the conventional receivedescriptor queue for performance reasons. Small transactions on PCI canseverely limit PCI bus throughput. In the typical receive descriptorenvironment a NIC must first read a descriptor (typically 16-32 bytes)across PCI to get the buffer information. It then moves the data acrossPCI into the buffer, and then writes status back into the receivedescriptor. One objective of our receive design was to eliminate thefirst descriptor read. Thus we needed an efficient way in which to passreceive buffer addresses to the INIC. We accomplished this by passing ablock of receive buffers to the INIC at one time. In the driver weallocate a block of contiguous memory (typically a page, which istypically 4 k). We write the address of that block to the INIC with thebottom bits of the address specifying the number of buffers in theblock. In order to receive 1514 byte frames (maximum ether frame size),however, we can only fit two buffers in a 4 k page, which is not asubstantial savings. Fortunately, network frames tend to be either large(˜1500 bytes), or small (<256 bytes).

[0114] We take advantage of this fact by allocating large and smallreceive buffers. If a received frame fits in a small buffer, the INICwill use a small buffer. Otherwise it will use a large buffer. A problemwith that system then is preserving receive order. If we were tomaintain a small and a large buffer queue, there would be no way to knowin which order two frames, one small and one large, were received. Asolution is to maintain a single receive queue of small buffers. Thehost passes the small buffers in blocks of 16 at a time to the INIC, andthey are guaranteed to be returned to us in the order in which they weregiven to the INIC. The small buffer contains status about the receive aswell as small frames. If a received frame does not fit in the smallbuffer, then we allocate a large buffer and place a pointer to thatlarge buffer in the small buffer. Thus, large buffers are only returnedto the driver when attached to small buffers.

[0115] As shown in FIG. 2, the fast-path flow puts a header such asHEADER A 90 into a header buffer that is then forwarded to the host.HEADER A contains status 92 that has been generated by the INIC andTCP/SMB headers 94 that can be used by the host to determine whatfurther data is following and allocate the necessary host buffers, whichare then passed back to the INIC as data buffer descriptors 96 via acommand to the INIC. The INIC then fills these buffers from data it wasaccumulating on the card and notifies the host by sending a response tothe command. Alternatively, the fast-path may receive a header and datathat is a complete request, but that is also too large for a headerbuffer. This results in a header and data buffer being passed to thehost. This latter flow is similar to the slow-path flow of HEADER B 98,which also puts all the data into the header buffer or, if the headerbuffer is too small, uses a large (2K) host buffer for all the data.This means that on the unsolicited receive path, the host will only seeeither a header buffer or a header and at most, one data buffer. Notethat data is never split between a header and a data buffer.

[0116] The order in which data is written is important. Data buffers aremoved by DMA into the host before the header buffer, since the headerbuffer contains the status word designating that the data has arrived.Header buffers in host memory are 256 bytes long, and are aligned on 256byte boundaries. There will be a field in the header buffer indicatingit has valid data. This field will initially be reset by the host beforepassing the buffer descriptor to the INIC. A set of header buffers arepassed from the host to the INIC by the host writing to the HeaderBuffer Address Register on the INIC. This register is defined asfollows:

[0117] Bits 31-8 Physical address in host memory of the first of a setof contiguous header buffers.

[0118] Bits 7-0 Number of header buffers passed.

[0119] In this way the host can, say, allocate 16 buffers in a 4K page,and pass all 16 buffers to the INIC with one register write. For eachinterface, the INIC will maintain a queue of these header descriptors inthe SmallHType queue in its own local memory, adding to the end of thequeue every time the host writes to one of the Header Buffer AddressRegisters. Note that the single entry is added to the queue; theeventual dequeuer will use the count after extracting that entry.

[0120] The header buffers will be used and returned to the host in thesame order that they were given to the INIC. The valid field will be setby the INIC before returning the buffer to the host. In this way a PCIinterrupt, with a single bit in the interrupt register, may be generatedto indicate that there is a header buffer for the host to process. Whenservicing this interrupt, the host will look at its queue of headerbuffers, reading the valid field to determine how many header buffersare to be processed.

[0121] Receive data buffers are allocated in blocks of two, 2 k byteseach (4 k page). In order to pass receive data buffers to the INIC, thehost must write two values to the INIC. The first value to be written isthe Data Buffer Handle. The buffer handle is not significant to theINIC, but will be copied back to the host to return the buffer to thehost. The second value written is the Data Buffer Address. This is thephysical address of the data buffer. When both values have been written,the INIC will add these values to FreeType queue of data bufferdescriptors. The INIC will extract two entries each time when dequeuing.

[0122] Data buffers will be allocated and used by the INIC as needed.For each data buffer used, the data buffer handle will be copied into aheader buffer. Then the header buffer will be returned to the host.

[0123] A transmit interface is shown in FIG. 3. The transmit interface,like the receive interface, has been designed to minimize the amount ofPCI bandwidth and latencies. In order to transmit data, the hosttransfers a command pointer 110 to the INIC. This command pointerincludes a command buffer handle 112, a command field 113, possibly aTCP context identification 114, and a list of physical data pointers116. The command buffer handle is defined to be the first word of thecommand buffer and is used by the host to identify the command. Thisword is passed back to the host in a response buffer queue, sincecommands may complete out of order as depicted by crossed arrows 118 and120, and the host needs to know which command is complete. Commands canbe used for many reasons, but primarily cause the INIC to transmit data,or to pass a set of buffers to the INIC for input data on the fast-pathas previously discussed.

[0124] Response buffers are physical buffers in host memory and containstatus 122 regarding the command as well as the command buffer handle.They are used by the INIC in the same order as they were given to theINIC by the host. This enables the host to know which response buffer(s)to next look at when the INIC signals a command completion.

[0125] Command buffers in host memory are a multiple of 32 bytes, up toa maximum of 1K bytes, and are aligned on 32 byte boundaries. A commandbuffer is passed to the INIC by writing to the Command Buffer AddressRegister for a given interface. This register is defined as follows:

[0126] Bits 31-5 Physical address in host memory of the command buffer.

[0127] Bits 4-0 Length of command buffer in bytes/32 (i.e. number ofmultiples of 32 bytes)

[0128] This is the physical address of the command buffer. For eachinterface we have a transmit command register and a receive commandregister. When one of these registers has been written, the INIC willadd the contents of the register to it's own internal queue of commandbuffer descriptors. The first word of all command buffers is defined tobe the command buffer handle. It is the job of the utility processor toextract a command from its local queue, DMA the command into a smallINIC buffer (from the FreeSType queue), and queue that buffer into theXmit#Type queue, where # is 0-3 depending on the interface, or theappropriate RCV queue. The receiving processor will service the queuesto perform the commands. When that processor has completed a command, itextracts the command buffer handle and passes it back to the host via aresponse buffer.

[0129] Response buffers in host memory are 32 bytes long and aligned on32 byte boundaries. They are handled in a very similar fashion to headerbuffers. There is a field in the response buffer indicating it has validdata. This field is initially reset by the host before passing thebuffer descriptor to the INIC. A set of response buffers are passed fromthe host to the INIC by the host writing to the Response Buffer AddressRegister on the INIC. This register is defined as follows:

[0130] Bits 31-8 Physical address in host memory of the first of a setof contiguous response buffers

[0131] Bits 7-0 Number of response buffers passed.

[0132] In this way the host can, say, allocate 128 buffers in a 4K page,and pass all 128 buffers to the INIC with one register write. The INICmaintains a queue of these header descriptors in its ResponseType queuefor each interface, adding to the end of the queue every time the hostwrites to the Response Buffer Address Register. The INIC writes theextracted contents including the count, to the queue in exactly the samemanner as for the header buffers.

[0133] The response buffers are used and returned to the host in thesame order that they were given to the INIC. The valid field is set bythe INIC before returning the buffer to the host. In this way a PCIinterrupt, with a single bit in the interrupt register, may be generatedto indicate that there is a response buffer for the host to process.When servicing this interrupt, the host will look at its queue ofresponse buffers, reading the valid field to determine how many responsebuffers are to be processed.

[0134]FIG. 4 shows an initial format of a thirty-two bit interruptstatus register (ISR) of the present invention. Bit thirty-one (ERR-131)is for setting error bits, bit thirty (RCV-130) denotes whether areceive has occurred, bit twenty-nine (CMD-129) denotes whether acommand has occurred, while bit twenty-five (RMISS-125) denotes whethera receive has occurred

[0135] It is designed that the setting of any bits in the ISR will causean interrupt, provided the corresponding bit in an Interrupt MaskRegister is set. The default setting for the IMR is 0.

[0136] It is also designed that the host should never need to directlyread the ISR from the INIC. To support this, it is important for thehost/INIC to arrange a buffer area in host memory into which the ISR isdumped. To accomplish this, the driver will write the location of thememory-based ISR to the Interrupt Status Pointer Register on the INIC.

[0137] For the host to never have to actually read the register from theINIC itself, it is important for the INIC to update this host copy ofthe register whenever anything in it changes. The host will Ack (ordeassert) events in the register by writing to the register with 0's inappropriate bit fields. So that the host does not miss events, thefollowing scheme is employed:

[0138] The INIC keeps a local copy of the register whenever the INICDMAs it to the host after some event(s). This is termed COPYA. Then theINIC starts accumulating any new events not reflected in the host copyin a separate word. This is called NEWA. As the host clears bits bywriting the register back with those bits set to zero, the INIC clearsthese bits in COPYA (or the host write-back goes directly to COPYA). Ifthere are new events in NEWA, it ORs them with COPYA, and DMAs this newISR to the host. This new ISR then replaces COPYA, NEWA is cleared andthe cycle then repeats.

[0139] Table 1 lists the INIC register addresses. For the sake ofsimplicity, the registers are in 4-byte increments from whatever the TBDbase address is. TABLE 1 ISP 0x0 Interrupt Status Pointer (0-3) ISR 0x10Interrupt Status Response (0-3) IMR 0x20 Interrupt Mask (0-3) HBAR 0x30Header Buffer Address (0-3) DBAR 0x40 Data Buffer Address (andHandle)(0-3) CBAR 0x50 Command Buffer Address XMT (0-3) RBAR 0x60Response Buffer Address (0-3) RCBAR 0x70 Receive Command Buffer Address

[0140] In order to coordinate operation of the INIC with a hostcomputer, we have designed an Alacritech TCP (ATCP) transport driver.The ATCP driver runs on the host and consists of three main components.The bulk of the protocol stack is based on the FreeBSD TCP/IP protocolstack. This code performs the Ethernet, ARP, IP, ICMP, and (slow path)TCP processing for the driver. At the top of the protocol stack weintroduce an NT filter driver used to intercept TDI requests destinedfor the Microsoft TCP driver. At the bottom of the protocol stack weinclude an NDIS protocol-driver interface which allows us to communicatewith the INIC miniport NDIS driver beneath the ATCP driver.

[0141] In order to ensure that our ATCP driver is written in aconsistent manner, we have adopted a set of coding guidelines. Theseproposed guidelines were introduced with the philosophy that we shouldwrite code in a Microsoft style since we are introducing an NT-basedproduct. The guidelines below apply to all code that we introduced intoour driver. Since a very large portion of our ATCP driver is based onFreeBSD, and since we were somewhat time-constrained in our driverdevelopment, the ported FreeBSD code is exempt from these guidelines.

Guidelines

[0142] Global symbols—All function names and global variables in theAtcp driver begin with the “ATK” prefix (ATKSend for instance).

[0143] We use the #define ALACRITECH to identify those sections of codewhich must be conditionally compiled (or not compiled) in the ATCP asopposed to BSD environment.

[0144] Variable names—Microsoft seems to use capital letters to separatemulti-word variable names instead of underscores (VariableName insteadof variable_name). We adhere to this style.

[0145] Structure pointers—Microsoft typedefs all of their structures.The structure types are always capitals and they typedef a pointer tothe structure as “P” <name> as follows: typedef struct_FOO {  INT bar; }FOO, *PFOO;

[0146] We adhere to this style.

[0147] Function calls—Microsoft separates function call arguments onseparate lines: X = foobar(  argument1,  argument2,  );

[0148] We adhere to this style.

[0149] Comments—While Microsoft seems to alternatively use // and /* */comment notation, we exclusively use the /* */ notation.

[0150] Function comments—Microsoft includes comments with each functionthat describe the function, its arguments, and its return value. We alsoinclude these comments, but move them from within the function itself tojust prior to the function for better readability.

[0151] Function arguments—Microsoft includes the keywords IN and OUTwhen defining function arguments. These keywords denote whether thefunction argument is used as an input parameter, or alternatively as aplaceholder for an output parameter. We include these keywords.

[0152] Function prototypes—as far as possible we collect all newfunction prototypes in a single file: atcp_prototypes.h. The practice ofproliferating a header file for every “.c” file is avoided. Prototypesof existing BSD functions are left in their current header files,however, to minimize differences between our code and the BSD base.

[0153] Indentation—Microsoft code fairly consistently uses a tabstop of4. We adhere to this style.

[0154] Header file #ifndef—each header file should contain a#ifndef/#define/#endif which is used to prevent recursive header fileincludes. For example, foo.h would include:

[0155] #ifndef _FOO_H_(—)

[0156] #define _FOO_H_(—)

[0157] <foo.h contents . . . >

[0158] #endif /* _FOO_H_*/

[0159] Note the _NAME_H_format.

[0160] Each file must contain a comment at the beginning which includesthe $Id$ as follows:

[0161] /*

[0162] * $Id$

[0163] */

[0164] CVS (RCS) will expand this keyword to denote RCS revision,timestamps, author, etc.

[0165] The next few paragraphs describe a configuration designed to makethe ATCP driver SMP safe. The basic rule for SMP kernel code is that anyaccess to a memory variable must be protected by a lock, which preventsa competing access by code running on another processor. Spinlocks arethe normal locking method for code paths that do not take a long time toexecute (and which do not sleep.)

[0166] In general each instance of a structure includes a spinlock,which must be acquired before members of that structure are accessed,and held while a function is accessing that instance of the structure.Structures which are logically grouped together may be protected by asingle spinlock: for example, the ‘in_pcb’ structure, ‘tcpcb’ structure,and ‘socket’ structure which together constitute the administrativeinformation for a TCP connection will be collectively managed by asingle spinlock in the corresponding connection object.

[0167] In addition, every global data structure such as a list or hashtable also has a protecting spinlock which must be held while thestructure is being accessed or modified. The NT DDK in fact provides anumber of convenient primitives for SMP-safe list manipulation, andthese are used for any new lists. Existing list manipulations in theFreeBSD code will be left as is to minimize code disturbance, except ofcourse that the necessary spinlock acquisition and release must be addedaround them.

[0168] Spinlocks should not be held for long periods of time, and mostespecially, must not be held during a sleep, since this will lead todeadlocks. There is a significant deficiency in the NT kernel supportfor SMP systems: it does not provide an operation, which allows aspinlock to be exchanged atomically for a sleep lock. This would be aserious problem in a UNIX environment where much of the processingoccurs in the context of the user process, which initiated theoperation. (The spinlock would have to be explicitly released, followedby a separate acquisition of the sleep lock: creating an unsafe window.)

[0169] The NT approach is more asynchronous, however: IRPs are simplymarked as ‘PENDING’ when an operation cannot be completed immediately.The calling thread does NOT sleep at that point: it returns, and may goon with other processing. Pending IRPs are later completed, not bywaking up the thread which initiated them, but by an ‘IoCompleteRequest’call which typically runs at DISPATCH level in an arbitrary context.

[0170] Thus we that have not in fact used sleep locks anywhere in thedesign of the ATCP driver, so hopefully the above issue will not arise.

[0171] As described above, the ATCP driver supports two paths forsending and receiving data, the fast-path and the slow-path. Thefast-path data flow corresponds to connections that are maintained onthe INIC, while slow-path traffic corresponds to network data for whichthe INIC does not have a connection. Note that in fast-path, all of thedata that flows between host and INIC is “pure payload”: all protocolprocessing is done on the INIC. In slow-path, however, the INIC isoperating as a conventional “dumb NIC”, and the packets passing betweenATCP driver and INIC contain all the header info from MAC layer on up.

[0172] For a first implementation, we divide network communication intoNETBIOS traffic, which is identifiable by port number, and everythingelse.

[0173] For NETBIOS input, as soon as the INIC has received a segmentcontaining a NETBIOS header, it will forward it up to the TCP driver,along with the NETBIOS length from the header. Alternatively the hostcan acquire this information from the header itself, but since the INIChas already done the decode, it seem reasonable to just pass it.

[0174] From the TDI spec, the amount of data in the buffer actually sentmust be at least 128 bytes. In fact, we have room for 192 bytes in our“small” buffers; and experiments show that, to make the NETBT coderespond correctly, it is necessary to pass more than 128 bytes. So for afull segment which starts with a NETBIOS header, we pass a “header” of192 bytes, together with the actual NETBIOS length, which will beindicated up as the “available” length. For segments less than a full1460 byte payload, all of the received segment will be forwarded; itwill be absorbed directly by the TDI client without any further memorydescriptor list (MDL) exchange. Experiments tracing the TDI data flowshow that the NETBT client directly absorbs up to 1460 bytes: the amountof payload data in a single Ethernet frame.

[0175] Once the INIC has passed to the host an indication with anNETBIOS length greater than the amount of data in the packet it passed,it goes into a state where it is expecting an MDL from the host; in thisstate, any further incoming data is accumulated in DRAM on the INIC.Overflow of INIC DRAM buffers will be avoided by using a receive windowof (currently) 8760 bytes on the INIC.

[0176] On receiving the indicated packet, the ATCP driver calls thereceive handler registered by the TDI client for the connection, passingthe actual size of the data in the packet from the INIC as “bytesindicated” and the NETBIOS length as “bytes available.”

[0177] In the “large data input” case, where “bytes available” exceedsthe packet length, the TDI client then provides an MDL, associated withan IRP, which must be completed when this MDL is filled. (This IRP/MDLmay come back either in the response to ATCP's call of the receivehandler, or as an explicit TDI_RECEIVE request.)

[0178] The ATCP driver builds a “receive request” from the MDLinformation, and passes this to the INIC. This request contains the TCPcontext identifier, size and offset information, a scatter/gather listof physical addresses corresponding to the MDL pages, a context field toallow the ATCP driver to identify the request on completion, and apiggybacked window update information (this will be discussed below).

[0179] Note: the ATCP driver must copy any remaining data (not taken bythe receive handler) from the header indicated by the INIC to the startof the MDL, and must adjust the size & offset information in the requestpassed to the INIC to account for this.

[0180] Once the INIC has been given the MDL, it will fill the givenpage(s) with incoming data up to the requested amount, and respond tothe ATCP driver when this is done. Note that the INIC maintains itsadvertised receive window as the maximum (currently 8760 bytes) whilefilling the MDL, to maximize throughput from the client.

[0181] On receiving the “receive request” response from the INIC, theATCP driver completes the IRP associated with this MDL, to tell the TDIclient that the data is available.

[0182] At this point the cycle of events is complete, and the ATCPdriver is now waiting for the next header indication.

[0183] In the general case we do not have a higher-level protocol headerto enable us to predict that more data is coming. The original idea wasto accumulate segments until a given amount (e.g. 8K) was available, andthen send a header to the host to cause it to provide an MDL in which toplace the data.

[0184] A problem with this approach is that the INIC would be requiredto close its advertised receive window as segments were accumulated,which would stall output from the sending client. To avoid this, weresorted (after some experimentation) to a subterfuge. On receiving aninitial full segment, the INIC sends a header of 192 bytes: but alsopasses a fictitious “available length” of (currently) 8760 bytes.

[0185] As in the NETBIOS case, if “bytes available” exceeds “bytesindicated”, the TDI client will provide an IRP with an MDL. The ATCPdriver will pass the MDL to the INIC to be filled, as before. The INICmoves succeeding incoming segments into the MDL: and since the grantingof the MDL may be regarded as a “promise” by the TDI client to acceptthe data, the INIC does not have to close its advertised receive windowwhile filling the MDL. The INIC will reply to the ATCP driver when ithas filled the MDL; the ATCP driver in turn completes the IRP to the TDIclient.

[0186] Of course, since there is no higher-level protocol to tell uswhat the actual data length is, it is possible (for protocols such asFTP and HTTP) to receive a FIN before the MDL is filled. In that case,we do a “short completion”, which causes the ‘information’ field of theIRP corresponding to the MDL to be set to the actual length received:less than the MDL size. Fortunately, WINSOCK clients (and the AFD driverthrough which they communicate with the TCP driver) appear to handlethis correctly.

[0187] If the INIC “owns” an MDL provided by the TDI client (sent by theATCP as a receive request), it will treat data placed in this as being“accepted by the client.” It may therefore ACK incoming data as it isfilling the pages, and will keep its advertised receive window fullyopen.

[0188] However, for small requests, there is no MDL returned by the TDIclient: it absorbs all of the data directly in the receive callbackfunction. In this case we need to update the INIC's view of data whichhas been accepted, so that it can update its receive window. In order tobe able to do this, the ATCP driver accumulates a count of data whichhas been accepted by the TDI client receive callback function for aconnection.

[0189] From the INIC's point of view, though, segments sent up to theATCP driver are just “thrown over the wall”; there is no explicit replypath. We therefore piggyback the update on requests sent out to theINIC. Whenever the ATCP driver has outgoing data for that connection, itplaces this count in a field in the send request (and then clears thecounter.) Receive requests (passing a receive MDL to the INIC) also areused to transport window update information in the same way.

[0190] Note that there is also a message path whereby the ATCP driverexplicitly sends an update of this “bytes consumed” information when itexceeds a preset threshold, to allow for scenarios in which the datastream is entirely one-way.

[0191] The fast-path transmit or output data flow is considerablysimpler. In this case the TDI client provides a MDL to the ATCP driveralong with an IRP to be completed when the data is sent. The ATCP driverthen gives a request (corresponding to the MDL) to the INIC. Thisrequest contains the TCP context identifier, size and offsetinformation, a scatter/gather list of physical addresses correspondingto the MDL pages, a context field to allow the ATCP driver to identifythe request on completion, and piggybacked window update information.

[0192] The INIC will copy the data from the given physical location(s)as it sends the corresponding network frames onto the network. When allof the data is sent, the INIC will notify the host of the completion,and the ATCP driver will complete the IRP.

[0193] Note that there may be multiple output requests pending at anygiven time. SMB allows multiple SMB requests to be simultaneouslyoutstanding, and other protocols (e.g. FTP) often use double-buffering.

[0194] For data for which there is no connection context beingmaintained on the INIC, the host performs the TCP, IP, and Ethernetprocessing (slow-path). To accomplish this, ATCP ports the FreeBSDprotocol stack. In this mode, the INIC is operating as a “dumb NIC”; thepackets which pass over the NDIS interface contain MAC-layer frames.

[0195] The memory buffers (MBUFs) in the incoming direction are in factmanaging NDIS-allocated packets. In the outgoing direction, we haveprotocol-allocated MBUFs in which to assemble the data and headers. TheMFREE macro is cognizant of the various types of MBUFs, and is able tohandle each type.

[0196] ATCP retains a modified socket structure for each connection,containing the socket buffer fields expected by the FreeBSD code. TheTCP calls that operate on socket buffers (adding/removing MBUFs to &from queues, indicating acknowledged & received data, etc.) remain (asfar as possible) unchanged in name and parameters from the FreeBSD base,though most of the actual code needed to implement them is rewritten.These are functions in kern/uipc_socket2.c; the corresponding ATCP codeis mostly in atksocket.c.

[0197] The upper socket layer (kern/uipc_socket.c), where the overlyingOS moves data in and out of socket buffers, must be entirelyre-implemented to work in TDI terms. Thus, instead of sosend( ), thereis a function that maps the MDL provided in a TDI_SEND call with a MBUFand queues it on to the socket ‘send’ buffer. Instead of soreceive( ),there is a handler that calls the TDI client receive callback function,and also copies data from socket receive buffer MBUFs into any MDLprovided by the TDI client (either explicitly with the callback responseor as a separate TDI_RECEIVE call.) Most of the functions in thiscategory are in the ATCP file atktdi.c.

[0198] Note that there is a semantic difference between TDI_SEND and awrite( ) on a BSD socket. The latter may complete back to its caller assoon as the data has been copied into the socket buffer. The completionof a TDI_SEND, however, implies that the data has actually been sent onthe connection. Thus we need to keep the TDI_SEND IRPs (and associatedMDLs) in a queue on the socket until the TCP code indicates that thedata from them has been ACK'd.

[0199] To pass a context from the ATCP to the INIC for processing viathe fast-path, a synchronization problem must be addressed. The ATCPdriver makes the decision when a given connection should be passed tothe INIC. The criterion is basically that the connection is on aninteresting protocol port, and is currently quiescent: i.e. there is nocurrently outstanding input or output data which would cause the TCPsequence fields to change as it is processed.

[0200] To initiate a handout to the INIC, the ATCP driver builds andsends a command identifying this connection to the INIC. Once this issent, ATCP pends and queues any new TDI_SEND requests; they will beacted on once fast-path processing is fully established.

[0201] The problem arises with incoming slow-path data. If we attempt todo the context-pass in a single command handshake, there is a windowduring which the ATCP driver has sent the context command, but the INIChas not yet acquired or has not yet completed setting up the context.During this time, slow-path input data frames could arrive and be fedinto the slow-path ATCP processing code. Should that happen, the contextinformation which the ATCP driver passed to the INIC would no longer becorrect. We could simply abort the outward pass of the context in thisevent, but it turns out that this scenario is quite common. So it seemsbetter to have a reliable handshake, which is accomplished with atwo-exchange handshake.

[0202] The initial command from ATCP to INIC expresses an “intention” tohand out the context. It carries a context number; context numbers areallocated by the ATCP driver, which keeps a per-INIC table of free andin use context numbers. It also includes the source and destination IPaddresses and ports, which will allow the INIC to establish a“provisional” context. Once it has this “provisional” context in place,the INIC will not send any more slow-path input frames to the host forthat src/dest IP/port combination, instead queuing them, if any arereceived.

[0203] Receipt of the response to this initial command does not sufficeto provide a reliable interlock, however. Command responses and dataframes follow entirely different paths from INIC to the ATCP driver. Itis possible that when the response to the initial command is received,there are still slow-path frames in a queue waiting to be delivered.Therefore, once the INIC has established its provisional context (and isnow blocking and queuing any further input), it sends a “NULL” interlockframe on the regular frame input path. This frame identifies the CCBcontext and signals that no further slow-path frames will follow forthat context. Since this frame travels on the same pathway as dataframes, we know when we receive it that it signifies the end of anypossible slow-path data.

[0204] Once the “NULL” frame has been seen (and any preceding slow-pathdata has been fully processed), we know that the CCB for the connectionis in a stable and quiescent state. At that point, the ATCP driverissues the second, “commit”, command to cause the INIC to fully activateits CCB context and begin normal fast-path processing.

[0205] Note that there are situations in which the ATCP driver decides,after having sent the original “intention” command, that the context isnot to be passed after all. (For example, the TDI client may issue aTDI_DISCONNECT, or a slow-path frame arriving before the NULL interlockframe might contain a FIN.) So we must allow for the possibility thatthe second command may be a “flush”, which should cause the INIC todeallocate and clear up its “provisional” context.

[0206] The ATCP driver must place some restrictions on exactly when a“flush” command may be sent, to avoid unnecessary complexity in the INICstate machine. Specifically, it must not send a “flush” command whenthere is an outstanding first- or second-half migration command. If aflush situation arises while a migration command is outstanding, thecondition is noted in host connection flags, and the actual flushcommand is sent only when the NULL frame is received (in the first-halfcase) or the command response is received (in the second-half case.)

[0207] The converse situation of passing the context from the INIC tothe ATCP may be initiated either by the ATCP driver or by the INIC. Themachinery for flushing the context from the INIC to the ATCP is similarregardless of which system initiated the transfer. If the ATCP driverwishes to cause context to be flushed from INIC to host, it sends a“flush” message to the INIC specifying the context number to be flushed.Once the INIC receives this, it proceeds with the same steps as for thecase where the flush is initiated by the INIC itself.

[0208] The INIC sends an error response to any current outstandingreceive request it is working on (corresponding to an MDL into whichdata is being placed.) Along with this response, it sends a “resid”field to reflect the amount of data that has not been placed in the MDLbuffers at the time of the flush. Likewise the INIC sends an errorresponse for any outstanding send requests. For each of these, it willsend a “resid” field to indicate how much of the request's data has notbeen ACK'd. The INIC also DMAs the CCB for the context back to the host.Note that part of the information provided with a context is the addressof the CCB in the host. The INIC sends a “flush” indication to the host,via the regular input path as a special type of frame, identifying thecontext which is being flushed. Sending this indication via the regularinput path ensures that it will arrive before any following slow-pathframes.

[0209] At this point, the INIC is no longer doing fast-path processing.It discards its CCB context for this connection, and any furtherincoming frames for the connection will simply be sent to the host asraw frames for the slow input path.

[0210] As soon as the ATCP driver detects that a flush is in progress ona connection, it sets a state flag on its connection context to indicatethis fact. The ATCP driver may become alerted about a flush in severalways: it might be an explicit host-initiated flush, or it may see eitherthe flush frame or an error on a send or receive request. The order inwhich these are received may vary because, as we noted earlier, thereceive frame and command response paths are unrelated.

[0211] The ATCP driver will not be abled to complete the cleanupoperations needed to resume normal slow path processing until all thenecessary pieces of information are received: the “flush frame”indicating that the INIC has DMA'd back the CCB, and the errorcompletions of all outstanding send and receive requests.

[0212] Slow-path frames could arrive during this time: this is why thedriver must set the “flushing” state flag on the connection. The effectof this is to change the behavior of tcp_input( ). This runs as afunction call in the context of ip_input( ), and normally returns onlywhen incoming frames have been processed as far as possible (queued onthe socket receive buffer or out-of-sequence reassembly queue.) However,if there is a flush pending and we have not yet completedresynchronization, we cannot do TCP processing and must instead queueinput frames for TCP on a “holding queue” for the connection, to bepicked up later when context flush is complete and normal slow pathprocessing resumes. (This is why we want to send the “flush” indicationvia the normal input path: so that we can ensure it is seen before anyfollowing frames of slow-path input.)

[0213] When the ATCP driver has received the “flush frame” plus errorresponses for all outstanding requests, it has all the informationneeded to complete its cleanup. This involves completing any IRPscorresponding to requests which have entirely completed, adjustingfields in partially-completed requests so that send and receive of slowpath data will resume at the right point in the byte streams andpropagating any timer expiration states from the INIC to the BSD code.

[0214] Once all this cleanup is complete, the ATCP driver will looppulling any “pended” TCP input frames off the “pending queue” mentionedabove and feeding them into the normal TCP input processing. After allinput frames on this queue have been cleared off, the “flushing” flagcan be cleared for the connection, and the host is back to normalslow-path processing.

[0215] A portion of the ATCP driver is either derived or directly takenfrom the FreeBSD TCP/IP protocol stack. The following paragraphs discussthe issues associated with porting this code, the FreeBSD code itself,and the modifications required for it to suit our needs. Note, however,that details of the higher, TCP-level part of the port are postponeduntil later, since this needs some groundwork from the discussion of theNT TDI interface.

[0216] FreeBSD TCP/IP (current version referred to as Net/3) is ageneral purpose TCP/IP driver. It contains code to handle a variety ofinterface types and many different kinds of protocols. To meet thisrequirement the code is often written in a sometimes confusing,convoluted manner. General-purpose structures are overlaid with otherinterface-specific structures so that different interface types cancoexist using the same general-purpose code. For our purposes much ofthis complexity is unnecessary since we are initially only supportingseveral specific protocols. It is therefore tempting to modify the codeand data structures in an effort to make it more readable, and perhaps abit more efficient. There are, however, some problems with doing this.

[0217] For this reason we have initially kept the data structures andcode at close to the original FreeBSD implementation as possible. Thecode has, however, been modified for several reasons. First, as requiredfor NT interaction—we can't expect to simply “drop-in” the FreeBSD codeas is. The interface of this code to the NT system requires somesignificant code modifications. This mostly occurs at the topmost andbottommost portions of the protocol stack, as well as the “ioctl”sections of the code. Modifications for SMP are also necessary. Further,unnecessary code has been removed.

[0218] The FreeBSD TCP/IP protocol stack makes use of many Unix systemservices. These include bcopy to copy memory, malloc to allocate memory,timestamp functions, etc. These will not be itemized in detail since theconversion to the corresponding NT calls is a fairly trivial andmechanical operation.

[0219] Under FreeBSD, network buffers are mapped using mbufs. Under NTnetwork buffers are mapped using a combination of packet descriptors andbuffer descriptors (the buffer descriptors are really MDLs). There are acouple of problems with the NT method. First it does not provide thenecessary fields which allow us to easily strip off protocol headers.Second, converting all of the FreeBSD protocol code to speak in terms ofbuffer descriptors is an unnecessary amount of overhead. Instead, in ourport we allocate our own mbuf structures and remap the NT packets asshown in FIG. 5.

[0220]FIG. 5 shows FreeBSD mbufs 140 and 142 including data pointers 150and 152, which point to the current location of the data, data lengthfields and flags. In addition each mbuf 155 and 157 will point to apacket descriptor 160 which is associated with the data being mapped.Once an NT packet is mapped, our transport driver should never have torefer to the packet or buffer descriptors 162 and 164 for anyinformation except when we are finished and are preparing to return thepacket.

[0221] There are a couple of things to note here. The INIC has beendesigned such that a packet header should never be split across multiplebuffers. Thus, we should never require the equivalent of the “m_pullup”routine included in Unix. Also note that there are circumstances inwhich we will be accepting data that will also be accepted by theMicrosoft TCP/IP. One such example of this is ARP frames. We also buildour own ARP cache by looking at ARP replies as they come off thenetwork. Under these circumstances, it is important that we do notmodify the data, or the packet and buffer descriptors. We will discussthis further below.

[0222] Also note that we allocate a pool of mbuf headers at ATCPinitialization time. It is important to remember that unlike other NICs,we do not simply drop data if we run out of the system resourcesrequired to manage/map the data. The reason for this is that we will bereceiving data from the card that has already been acknowledged by TCP.Because of this it is important that we never run out of mbuf headers.To solve this problem we statically allocate mbuf headers for themaximum number of buffers that we will ever allow to be outstanding. Bydoing so, the card will run out of buffers in which to put the databefore we will run out of mbufs, and as a result, the card will beforced to drop data at the link layer instead of us dropping it at thetransport layer.

[0223] We also use a pool of actual mbufs (not just headers). Thesembufs are needed in order to build output packets for the slow-path datapath, as well as other miscellaneous purposes such as for building ARPrequests. We allocate a pool of these at initialization time and add tothis pool dynamically as needed. Unlike the mbuf headers describedabove, which are used to map acknowledged TCP data coming from the card,the full mbufs contain data that can be dropped if we cannot get anmbuf.

[0224] The following paragraphs describe the lower-level sections of theFreeBSD TCP/IP port, up to and including the IP level. These sectionsinclude Interface Initialization, ARP, Route, IP, and ICMP. Discussionsof modifications to the TCP layer are postponed, since they need somegrounding in the NT TDI interface described below.

[0225] There are a variety of structures, which represent a singleinterface in FreeBSD. These structures include ifnet, arpcom, ifaddr,in_ifaddr, sockaddr, sockaddr_in, and sockaddr_dl.

[0226]FIG. 6 shows the relationship between some of these structures. Inthis example we show a single interface with a MAC address(sockaddr_dl-170) of 00:60:97:DB:9B:A6 configured with an IP address(sockaddr_in-172) of 192.100.1.2. As illustrated above, the in_ifaddr175 is actually an ifaddr 177 structure with some extra fields tacked onto the end. Thus the ifaddr structure is used to represent both a MACaddress and an IP address. Similarly the sockaddr structure is recast asa sockaddr_dl or a sockaddr_in depending on its address type. Aninterface can be configured to multiple IP addresses by simply chainingin_ifaddr structures after the in_ifaddr structure shown above. Asmentioned in the porting philosophy section, many of the abovestructures could likely be collapsed into fewer structures. In order toavoid making unnecessary modifications to FreeBSD, for the time being wehave these structures mostly unchanged. We have, however, eliminated thefields from the structure that will never be used. These structuremodifications are discussed below.

[0227] We also show in FIG. 6 a structure called IFACE 180. This is astructure that we define, in proto.h. It contains the arpcom 182structure, which in turn contains the ifnet 185 structure. It alsocontains fields that enable us to blend our FreeBSD implementation withNT NDIS requirements. One such example is the NDIS binding handle usedto call down to NDIS with requests (such as send).

[0228] FreeBSD initializes the above structures in two phases. Firstwhen a network interface is found, the ifnet, arpcom, and first ifaddrstructures are initialized first by the network layer driver, and thenvia a call to the if_attach routine. The subsequent in_ifaddrstructure(s) are initialized when a user dynamically configures theinterface. This occurs in the in_ioctl and the in_ifinit routines.

[0229] Interface initialization in the ATCP driver changes considerablyfrom BSD, because in NT, many parameters are obtained from the registry,rather than being set by IOCTL( ) calls. Initialization still occurs intwo phases, but the details are different:

[0230] ATKIfInit is called from the DriverEntry function when the ATCPdriver is loaded. It scans the registry, looking for all interfacesbound to TCP/IP. For each one, it allocates an IFACE structure, and doesfurther registry scanning to obtain parameters for this interface. Oncethese are obtained, it calls if_attach( ), which allocates the ifaddrstructure for the interface, and links it on to the BSD interface list.Then, for each IP address specified in the registry for this interface(there may be more than one), it builds an ifaliasreq structurecontaining the address and its netmask, and calls in_control with theSIOCAIFADDR command to allocate and initialize the in_ifaddr andsockaddr_in structures; this has the side effect of creating the routesfor the interface. (Note however that if the interface is specified inthe registry to use DHCP there are no IP addresses at this point; inthat case a flag is set in the IFACE to indicate that DHCP is to beused.) Finally, if a default gateway is specified for the interface, acall is made to ATKAddDefRoute (in file atkroute.c) to add this to theroute tables.

[0231] Note that so far, everything has been done from information inthe registry; we do not yet have any contact with physical hardware.That occurs in the second phase, when NDIS calls our ATKBindAdaptorfunction to set up the connection to the actual NDIS-level adaptor:

[0232] ATKBindAdaptor locates the IFACE for the given adaptor name, anddoes a query request to NDIS to obtain the MAC address for theinterface; this is saved in the arpcom struct. It then does a number ofother queries for characteristics of the interface and stores theresults in the IFACE. Next, it passes down all current IP addressesusing an Alacritech-specific OID: this is needed because the INIC driverat the lower level needs to know about IP addresses in order to directpackets correctly to either the ATCP driver or the regular NT TCP/IPdriver (see section 9.2.1.) Finally it marks the interface up, andbroadcasts a gratuitous ARP request to notify others of our Mac/IPaddress and to detect duplicate IP addresses on the net.

[0233] Microsoft NT TCP/IP code supports the Dynamic Host ConfigurationProtocol (DHCP), whereby one can arrange for an interface to not beassigned a static IP address, but rather, to search for a DHCP server toassign one for it to use. In this case ATKIfInit does not find anaddress in the registry for the interface: it will arrive later in aDEVICE_IO_CONTROL on the IP device object. Our filter driver attaches toand monitors the IP device object as well as the TCP one.

[0234] We catch the completion of the IOCTL_SET_DHCPADDR request in theATKDHCPDone function (in file atkdhcp.c); there, we decode theparameters and locate the interface. Then we call the BSD in_controlfunction to set the IP address and netmask, and replicate the later partof the ATKBindAdaptor processing (which can't be done there in the caseof a DHCP interface since we don't yet have an IP address) to completethe process of making the interface active.

[0235] The DHCP protocol provides a time-limited “lease” of an IPaddress: this implies that DHCP IP addresses can go away, as well asarrive. If we detect that the DHCP IO_CONTROL is a deletion, we mustmark the interface down, and delete any routes using it. Additionally,we need to flush any fast-path connections using this interface back tothe host; this is done by the ATKIfRouteFlush( ) function (inatkfastpath.c.)

[0236] We port the FreeBSD ARP code to NT mostly as-is. For some reason,the FreeBSD ARP code is located in a file called if_ether.c. While we donot change the functionality of this file, we rename it to a morelogical arp.c. The main structures used by ARP are the llinfo_arpstructure and the rtentry structure (actually part of route). Thesestructures do not require major modifications. The functions thatrequire modification are defined here.

[0237] An in_arpinput function is called to process an incoming ARPframe. An ARP frame can either be an ARP request or an ARP reply. ARPrequests are broadcast, so we will see every ARP request on the network,while ARP replies are directed so we should only see ARP replies thatare sent to us. This introduces several scenarios for an incoming ARPframe.

[0238] First, an ARP request may be trying to resolve our IP address.Under conventional circumstances, ARP would reply to this ARP requestwith an ARP reply containing our MAC address. Since ARP requests willalso be passed up to the Microsoft TCP/IP driver, we need not reply.Note however, that FreeBSD also creates or updates an ARP cache entrywith the information derived from the ARP request. It does this inanticipation of the fact that any host that wishes to know our MACaddress is likely to wish to talk to us soon. Since we need to know hisMAC address in order to talk back, we add the ARP information now ratherthan issuing our own ARP request later.

[0239] Second, an ARP request may be trying to resolve someone else's IPaddress. As mentioned above, since ARP requests are broadcast, we seeevery one on the network. When we receive an ARP request of this type,we simply check to see if we have an entry for the host that sent therequest in our ARP cache. If we do, we check to see if we still have thecorrect MAC address associated with that host. If it is incorrect, weupdate our ARP cache entry. Note that we do not create a new ARP cacheentry in this case.

[0240] Third, in the case of an ARP reply, we add the new ARP entry toour ARP cache. Having resolved the address, we check to see if there isany transmit requests pending for the resolve IP address, and if so,transmit them.

[0241] Given the above three possibilities, the only major change to thein_arpinput code is that we remove the code which generates an ARP replyfor ARP requests that are meant for our interface.

[0242] Arpintr is the FreeBSD code that delivers an incoming ARP frameto in_arpinput. We call in_arpinput directly from our ProtocolReceiveDPCroutine (discussed in the NDIS section below) so this function is notneeded.

[0243] Arpwhohas is a single line function that serves only as a wrapperaround arprequest. We remove it and replace all calls to it with directcalls to arprequest.

[0244] Arprequest simply allocates a mbuf, fills it in with an ARPheader, and then passes it down to the ethernet output routine to betransmitted. For us, the code remains essentially the same except forthe obvious changes related to how we allocate a network buffer, and howwe send the filled in request.

[0245] Arp_ifinit is called when an interface is initialized tobroadcast a gratuitous ARP request (described in the interfaceinitialization section) and to set some ARP related fields in the ifaddrstructure for the interface. We simply move this functionality into theinterface initialization code and remove this function.

[0246] Arptimer is a timer-based function that is called every 5 minutesto walk through the ARP table looking for entries that have timed out.Although the time-out period for FreeBSD is 20 minutes, RFC 826 does notspecify any timer requirements with regard to ARP so we can modify thisvalue or delete the timer altogether to suit our needs. Either way thefunction doesn't require any major changes.

[0247] Other functions in if_ether.c do not require any major changes.

[0248] On first thought, it might seem that we have no need for routingsupport since our ATCP driver will only receive IP datagrams whosedestination IP address matches that of one of our own interfaces.Therefore, we do not “route” from one interface to another. Instead, theMICROSOFT TCP/IP driver provides that service. We do, however, need tomaintain an up-to-date routing table so that we know a) whether anoutgoing connection belongs to one of our interfaces, b) to whichinterface it belongs, and c) what the first-hop IP address (gateway) isif the destination is not on the local network.

[0249] We discuss four aspects on the subject of routing in thissection. They are as follows: 1) The mechanics of how routinginformation is stored, 2) The manner in which routes are added ordeleted from the route table, 3) When and how route information isretrieved from the route table, 4) Notification of route table changesto interested parties.

[0250] In FreeBSD, the route table is maintained using an algorithmknown as PATRICIA (Practical Algorithm To Retrieve Information Coded inAlphanumeric). This is a complicated algorithm that is a bit costly toset up, but is very efficient to reference. Since the routing tableshould contain the same information for both NT and FreeBSD, and sincethe key used to search for an entry in the routing table will be thesame for each (the destination IP address), we port the routing tablesoftware to NT without any major changes.

[0251] The software which implements the route table (via the PATRICIAalgorithm) is located in the FreeBSD file, radix.c. This file is porteddirectly to the ATCP driver with insignificant changes.

[0252] Routes can be added or deleted in a number of different ways. Thekernel adds or deletes routes when the state of an interface changes orwhen an ICMP redirect is received. User space programs such as the RIPdaemon, or the route command also modify the route table.

[0253] For kernel-based route changes, the changes can be made by adirect call to the routing software. The FreeBSD software that isresponsible for the modification of route table entries is found inroute.c. The primary routine for all route table changes is calledrtrequesto. It takes as its arguments the request type (ADD, RESOLVE,DELETE), the destination IP address for the route, the gateway for theroute, the netmask for the route, the flags for the route, and a pointerto the route structure (struct rtentry) in which we place the added orresolved route. Other routines in the route.c file include rtinit( ),which is called during interface initialization time to add a staticroute to the network, rtredirect, which is called by ICMP when wereceive a ICMP redirect, and an assortment of support routines used forthe modification of route table entries. All of these routines found inroute.c are ported with no major modifications.

[0254] For user-space-based changes, we will have to be a bit moreclever. In FreeBSD, route changes are sent down to the kernel fromuser-space applications via a special route socket. This code is foundin the FreeBSD file, rtsock.c. Obviously this will not work for our ATCPdriver. Instead the filter driver portion of our driver will interceptroute changes destined for the Microsoft TCP driver and will apply thosemodifications to our own route table via the rtrequest routine describedabove. In order to do this, it will have to do some format translationto put the data into the format (sockaddr_in) expected by the rtrequestroutine. Obviously, none of the code from rtsock.c will be ported to theATCP driver. This same procedure will be used to intercept and processexplicit ARP cache modifications.

[0255] The functions which perform these updates areATKSetRouteCompletion( ) and ATKSetArpCompletion( ), in the fileatkinfo.c

[0256] In FreeBSD, a route table is consulted in ip_output when an IPdatagram is being sent. In order to avoid a complete route table searchfor every outgoing datagram, the route is stored into the in_pcb for theconnection. For subsequent calls to ip_output, the route entry is thensimply checked to ensure validity. While we will keep this basicoperation as is, we require a slight modification to allow us to coexistwith the Microsoft TCP driver. When an active connection is being setup, our filter driver has to determine whether the connection is goingto be handled by one of the INIC interfaces. To do this, we consult theroute table from the filter driver portion of our driver. This is donevia a call to the rtalloc1 function (found in route.c). If a valid routetable entry is found, then we take control of the connection and set apointer to the rtentry structure returned by rtalloc1 in our in_pcbstructure.

[0257] When a route table entry changes, there may be connections thathave pointers to a stale route table entry. These connections need to benotified of the new route. FreeBSD solves this by checking the validityof a route entry during every call to ip_output. If the entry is nolonger valid, its reference to the stale route table entry is removed,and an attempt is made to allocate a new route to the destination. Forthe slow-path, this works fine. Unfortunately, since our IP processingis handled by the INIC for the fast-path, this sanity check method willnot be sufficient. Instead, we will need to perform a review of all ofour fast path connections during every route table modification. If theroute table change affects our connection, we flush the connection offthe INIC, so that we revert to slow-path processing using the BSD TCPprotocol code. This picks up the new route, and uses this to build a newtemplate when the connection is later handed out to the INIC again. Thefunction which performs this scan-and-flush is ATKRouteFlush( ), in fileatkfastpath.c.

[0258] Like the ARP code above, we need to process certain types ofincoming ICMP frames. Of the 10 possible ICMP message types, there areonly three that we need to support. These include ICMP_REDIRECT,ICMP_UNREACH, and ICMP_SOURCEQUENCH. Any FreeBSD code to deal with othertypes of ICMP traffic will be removed. Instead, we simply returnNDIS_STATUS_NOT_ACCEPTED for all but the above ICMP frame types. Thefollowing paragraphs describe how we handle these ICMP frames.

[0259] Under FreeBSD, an ICMP_REDIRECT causes two things to occur.First, it causes the route table to be updated with the route given inthe redirect. Second, it results in a call back to TCP to cause TCP toflush the route entry attached to its associated in_pcb structures. Bydoing this, it forces ip_output to search for a new route. As mentionedin the Route section above, we also require a call to a routine whichreviews all of the TCP fast-path connections, and flushes any using theaffected route.

[0260] In both FreeBSD and Microsoft TCP, the ICMP_UNREACH results in nomore than a simple statistic update. We do the same.

[0261] A source quench is sent to cause a TCP sender to close itscongestion window to a single segment, thereby putting the sender intoslow-start mode. We keep the FreeBSD code as-is for slow-pathconnections. For fast path connections we must flush the context back tothe host, since we are not, at least at the moment, handling congestionand slow-start on the INIC.

[0262] The FreeBSD IP code requires few modifications when porting tothe ATCP driver, which are described in the paragraphs below.

[0263] During initialization time, ip_init is called to initialize thearray of protosw structures. These structures contain all theinformation needed by IP to be able to pass incoming data to the correctprotocol above it. We strip the protosw array to exclude unnecessaryprotocols.

[0264] Changes made to IP input (function ip_intr( )) are listed below.

[0265] First, since we only handle datagrams for which we are the finaldestination, we are never required to forward an IP datagram. Allreferences to IP forwarding, and the ip_forward function itself, areremoved. IP options supported by FreeBSD at this time include recordroute, strict and loose source and record route, and timestamp. For thetimestamp Option, FreeBSD only logs the current time into the IP headerbefore it is forwarded. Since we will not be forwarding IP datagrams,this seems to be of little use to us. While FreeBSD supports theremaining options, NT essentially does nothing useful with them.

[0266] There is a small problem with the FreeBSD IP reassembly code. Thereassembly code reuses the IP header portion of the IP datagram tocontain IP reassembly queue information. It can do this because it nolonger requires the original IP header. This is an absolute no-no withthe NDIS 4.0 method of handling network packets. The NT DDK explicitlystates that we must not modify packets given to us by NDIS. This is notthe only place in which the FreeBSD code modifies the contents of anetwork buffer. It also does this when performing endian conversions. Atthe moment we leave this code as is and violate the DDK rules. We can dothis because we ensure that no other transport driver looks at theseframes. If this changes, we can modify this code substantially by movingthe IP reassembly fields into the mbuf header.

[0267] Regarding IP output, only two modifications are made. The firstis that since, for the moment, we are not dealing with IP options, thereis no need for the code that inserts the IP options into the IP header.Second, we may discover that it is impossible for us to ever receive anoutput request that requires fragmentation. Since TCP performs MaximumSegment Size negotiation, we should theoretically never attempt to senda TCP segment larger than the MTU.

[0268] An NDIS Protocol Driver portion of the ATCP driver is defined bythe set of routines registered with NDIS via a call toNdisRegisterProtocol. These routines are limited to those that arecalled (indirectly) by the INIC miniport driver beneath us. For example,we register a ProtocolReceivePacket routine so that when the INIC drivercalls NdisMIndicateReceivePacket it will result in a call from NDIS toour driver.

[0269] The NDIS protocol driver initialization occurs in two phases. Thefirst phase occurs when the ATCP DriverEntry routine callsATKProtoSetup. The ATKProtoSetup routine allocates resources, registersprotocol and locates and initializes bound NICs. We attempt to allocatemany of the required resources as soon as possible so that we are morelikely to get the memory we want. This mostly applies to allocating andinitializing our mbuf and mbuf header. pools. We callNdisRegisterProtocol to register our set of protocol driver routines.The location and initializion of bound NICs is done by ATKIfInit, asdescribed above.

[0270] After the underlying INIC devices have completed theirinitialization, NDIS calls our driver's ATKBindAdapter function for eachunderlying device. This completes the interface initialization.

[0271] Receive is handled by the protocol driver routineATKReceivePacket. Before we describe this routine, consider eachpossible receive type and how it will be handled. As shown in FIG. 7,the INIC miniport driver 200 is bound to the ATCP transport driver 202as well as the generic Microsoft TCP driver 205, and optionally others.The ATCP driver 202 is bound exclusively to INIC devices, while thegeneric TCP driver 205 is bound to the INIC as well as otherconventional NICs, as indicated by its connection to a generic miniportdriver 208 as well as the INIC miniport driver 200.

[0272] By binding the drivers in this fashion, we can choose to directincoming network data to our own ATCP transport driver, the MicrosoftTCP driver, or both. We do this by playing with the ethernet “type”field as follows. To NDIS and the transport drivers above it, the INICis registered as a normal ethernet card. When the generic TCP/IPtransport driver receives a packet from the INIC driver, it will expectthe data to start with an ethernet header, and consequently, expects theprotocol type field to be in byte offset 12. If Microsoft TCP finds thatthe protocol type field is not equal to either IP, or ARP, it will notaccept the packet. So, to deliver an incoming packet to our driver, wesimply map the data such that byte 12 contains a non-recognized ethernettype field. Note that we choose a value that is greater than 1500 bytesso that the transport drivers do not confuse it with an 802.3 frame. Wealso choose a value that will not be accepted by other transport driversuch as Appletalk or IPX. Similarly, if we want to direct the data toMicrosoft TCP, we can then simply leave the ethernet type field set toIP (or ARP). Note that since we will also see these frames we can chooseto accept or not-accept them as necessary.

[0273] Incoming packets delivered to ATCP only (not accepted by MSTCP)include TCP, TTCP or SPX packets destined for one of our IP addresses.This includes both slow-path frames and fast-path frames. In theslow-path case, the TCP frames are given in their entirety (headersincluded). In the fast-path case, the ATKReceivePacket is given a headerbuffer that contains status information and data with no headers (exceptthose above TCP).

[0274] Incoming packets delivered to Microsoft TCP only (not accepted byATCP) are packets according to protocol not suitable for the fast-path(non-TCP, TTCP or SPX packets) or packets that are not destined for oneof our interfaces (packets that will be routed). If in the aboveexample, there is an IP address 144.48.252.4 associated with a 3cominterface, and we receive a TCP connect with a destination IP address of144.48.252.4, we will actually want to send that request up to the ATCPdriver so that we create a fast-path connection for it. This means thatwe need to know every IP address in the system and filter frames basedon the destination IP address in a given TCP datagram. This is done inthe INIC miniport driver. Since the ATCP driver learns of dynamic IPaddress changes in the system, we notify the INIC miniport of all the IPaddresses in the system.

[0275] Incoming packets delivered to both ATCP and Microsoft TCP includeARP frames and ICMP frames

[0276] There are several circumstances in which the INIC will need toindicate extra information about a receive packet to the ATCP driver.One such example is a fast path receive in which the ATCP driver needsto be notified of how much data the card has buffered. To accomplishthis, the first (and sometimes only) buffer in a received packet willactually be a INIC header buffer. The header buffer contains statusinformation about the receive packet, and may or may not contain networkdata as well. The ATCP driver recognizes a header buffer by mapping itto an ethernet frame and inspecting the type field found in byte 12. Weindicate all TCP frames destined for us in this fashion, while framesthat are destined for both our driver and the Microsoft TCP driver (ARP,ICMP) are indicated without a header buffer.

[0277]FIG. 8A shows an example of an incoming TCP packet, whereas FIG.8B shows an example of an incoming ARP frame, after processing by theINIC.

[0278] NDIS has been designed such that all packets indicated viaNdisMIndicateReceivePacket by an underlying miniport are delivered tothe ProtocolReceivePacket routine for all protocol drivers bound to it.These protocol drivers can choose to accept or not accept the data. Theycan either accept the data by copying the data out of the packetindicated to it, or alternatively they can keep the packet and return itlater via a call to NdisReturnPackets. By implementing it in thisfashion, NDIS allows more than one protocol driver to accept a givenpacket. For this reason, when a packet is delivered to a protocoldriver, the contents of the packet descriptor, buffer descriptors anddata must all be treated as read-only. At the moment, we violate thisrule. We choose to violate this because much of the FreeBSD codemodifies the packet headers as it examines them (mostly for endianconversion purposes). Rather than modify all of the FreeBSD code, wewill instead ensure that no other transport driver accepts the data bymaking sure that the ethernet type field is unique to us (no one elsewill want it). Obviously this only works with data that is onlydelivered to our ATCP driver. For ARP and ICMP frames we instead copythe data out of the packet into our own buffer and return the packet toNDIS directly. While this is less efficient than keeping the data andreturning it later, ARP and ICMP traffic should be small enough, andinfrequent enough, that it doesn't matter.

[0279] The DDK specifies that when a protocol driver chooses to keep apacket, it should return a value of 1 (or more) to NDIS in itsProtocolReceivePacket routine. The packet is then later returned to NDISvia the call to NdisReturnPackets. This can only happen after theProtocolReceivePacket has returned control to NDIS. This requires thatthe call to NdisReturnPackets must occur in a different executioncontext. We accomplish this by scheduling a DPC, or alternativelyscheduling a system thread, or scheduling a kernel thread of our own. ADPC requires a queue of pending receive buffers on which to place andfetch receive packets.

[0280] After a receive packet is dequeued by the DPC it is then eitherpassed to TCP directly for fast-path processing, or it is sent throughthe FreeBSD path for slow-path processing. Note that in the case ofslow-path processing, we may be working on data that needs to bereturned to NDIS (for example TCP data) or we may be working on our owncopy of the data (ARP and ICMP). When we finish with the data we willneed to figure out whether or not to return the data to NDIS or not.This will be done via fields in the mbuf header used to map the data.When the mfreem routine is called to free a chain of mbufs, the fieldsin the mbuf will be checked and, if required, the packet descriptorpointed to by the mbuf is returned to NDIS.

[0281] As noted in the section on mbufs above, we map incoming data tombufs so that our FreeBSD port requires fewer modifications. Dependingon the type of data received, this mapping will appear differently.

[0282]FIG. 9A shows incoming data packet 245 for a TCP fast-pathconnection. In this example, the TCP data 250 is fully contained in aheader buffer 255. The header buffer is mapped by the mbuf 257 and sentupstream for fast-path TCP processing. In this case it is required thatthe header buffer be mapped and sent upstream because the fast-path TCPcode needs information contained in the header buffer in order toperform the processing. When the mbuf in this example is freed, themfreem routine will determine that the mbuf maps a packet that is ownedby NDIS and will then free the mbuf header only and callNdisReturnPackets to free the data.

[0283] In FIG. 9B, we show incoming data packet 260 for a TCP slow-pathconnection. In this example the mbuf 264 points to the start of the TCPdata 266 directly instead of to a header buffer 268. Since a data buffer270 will be sent up for slow-path FreeBSD processing, we cannot have thembuf pointing to the header buffer (FreeBSD would get awfully confused).Again, when mfreem is called to free the mbuf, it will discover themapped packet, free the mbuf header, and call NDIS to free the packetand return the underlying buffers. Note that even though we do notdirectly map the header buffer with the mbuf we do not lose it becauseof the link from the packet descriptor. Note also that we couldalternatively have the INIC miniport driver only pass us the TCP databuffer when it receives a slow-path receive. This would work fine exceptthat we have determined that even in the case of slow-path connectionswe are going to attempt to offer some assistance to the host TCP driver(most likely by checksum processing only). In this case there may besome special fields that we need to pass up to the ATCP driver from theINIC driver. Leaving the header buffer connected seems the most logicalway to do this.

[0284] In FIG. 9C shows a received ARP frame. Recall that for incomingARP and ICMP frames we can copy the incoming data out of the packet andreturn it directly to NDIS. In this case the mbuf 275 simply points toour data 278, with no corresponding packet descriptor. When we free thismbuf, mfreem will discover this and free not only the mbuf header, butthe data as well.

[0285] This receive mechanism may also be used for other purposesbesides the reception of network data. For instance, the receivemechanism may be used for communication between the ATCP driver and theINIC. One such example is a TCP context flush from the INIC. When theINIC determines, for whatever reason, that it can no longer manage a TCPconnection, it must flush that connection to the ATCP driver. It doesthis by filling in a header buffer with appropriate status anddelivering it to the INIC driver. The INIC driver in turn delivers it tothe protocol driver which will treat it essentially like a fast-path TCPconnection by mapping the header buffer with an mbuf header anddelivering it to TCP for fast-path processing. There are two advantagesto communicating in this manner. First, it is already an establishedpath, so no extra coding or testing is required. Second, since a contextflush comes in, in the same manner as received frames, it will preventus from getting a slow-path frame before the context has been flushed.

[0286] Having covered the various types of receive data at least for theTCP example, following are the steps that must be taken by theATKProtocolReceivePacket routine. Incoming data is mapped to an ethernetframe and the type field is checked. If the type field contains ourcustom INIC type (TCP for example), and if the header buffer specifies afast-path connection, allocate one or more mbufs headers to map theheader and possibly data buffers. Set the packet descriptor field of thembuf to point to the packet descriptor, set the mbuf flagsappropriately, queue the mbuf, and return 1. If the header bufferspecifies a slow-path connection, allocate a single mbuf header to mapthe network data, set the mbuf fields to map the packet, queue the mbufand return 1. Note that we design the INIC such that we will never get aTCP segment split across more than one buffer.

[0287] If the type field of the frame instead indicates ARP or ICMP, ambuf with a data buffer is allocated, the contents of the packet arecopied into the mbuf, the mbuf is queued, and return 0 (not accepted).If the type field is not INIC, ARP or ICMP type, ATCP does not processthe packet, and so return 0.

[0288] The receive processing will continue when the mbufs are dequeued.At the moment we will assume this is done by a routine calledATKProtocolReceiveDPC. It will dequeue a mbuf from the queue. andinspect the mbuf flags. If the mbuf is meant for fast-path TCP, it willcall the fast-path routine directly. Otherwise it will call the ethernetinput routine for slow-path processing.

[0289] The ATCP transmit path is discussed in the following paragraphs,beginning with the NDIS 4 send operation. When a transport/protocoldriver wishes to send one or more packets down to an NDIS 4 miniportdriver, it calls NdisSendPackets with an array of packet descriptors tosend. As soon as this routine is called, the transport/protocol driverrelinquishes ownership of the packets until they are returned, one byone in any order, via a NDIS call to the ProtocolSendComplete routine.Since this routine is called asynchronously, our ATCP driver must saveany required context into the packet descriptor header so that theappropriate resources can be freed. This is discussed further below.

[0290] Like the Receive path described above, the Transmit path is usednot only to send network data, but is also used as a communicationmechanism between the host and the INIC. Some examples of the types ofsends performed by the ATCP driver follow.

[0291]FIG. 10 illustrates a fast-path send. When the ATCP driverreceives a transmit request with an associated MDL 300 from a clientsuch as a host application, it packages up the MDL physical addressesinto a command buffer 303, maps the command buffer with a bufferdescriptor 305 and a packet descriptor 308, and calls NdisSendPacketswith the corresponding packet. The underlying INIC driver will issue thecommand buffer to the INIC. When the corresponding response buffer isgiven back to the host, the INIC miniport calls NdisMSendComplete whichwill result in a call to the ATCP ProtocolSendComplete (ATKSendComplete)routine, at which point the resources (data 313) associated with thesend can be freed. We allocate and use a mbuf 310 to hold the commandbuffer. By doing this we can store the context necessary in order toclean up after the send completes. This context includes a pointer tothe MDL as well as other connection context. The other advantage tousing a mbuf to hold the command buffer is that it eliminates havinganother special set of code to allocate and return command buffer. Westore a pointer to the mbuf in the reserved section of the packetdescriptor so we can locate it when the send is complete.

[0292] As described above, the receive process typically occurs in twophases. First the INIC fills in a host receive buffer with a relativelysmall amount of data, but notifies the host of a large amount of pendingdata (either through a large amount of buffered data on the card, orthrough a large amount of expected NetBios data). This small amount ofdata is delivered to the client through the TDI interface. The clientthen responds with a MDL in which the data should be placed. Like theFast-path TCP send process, the receive portion of the ATCP driver willthen fill in a command buffer with the MDL information from the client,map the buffer with packet and buffer descriptors and send it to theINIC via a call to NdisSendPackets. Again, when the response buffer isreturned to the INIC miniport, the ATKSendComplete routine will becalled and the receive will complete. This relationship between the MDL,command buffer and buffer and packet descriptors are the same as shownin the Fast-path send section above.

[0293]FIG. 11 illustrates a slow-path send. Slow-path sends pass throughthe FreeBSD stack until the ethernet header is prepended in ether_outputand the packet is ready to be sent. At this point a command buffer willbe filled with pointers to the ethernet frame, the command buffer willbe mapped with a packet descriptor 315 and a buffer descriptor 318 andNdisSendPackets will be called to hand the packet off to the miniport.FIG. 11 shows the relationship between the mbufs, command buffer, andbuffer and packet descriptors. Since we will use a mbuf 320 to map thecommand buffer 322, we can simply link the data mbufs 325 directly offof the command buffer mbuf. This will make the freeing of resources muchsimpler.

[0294] As shown in FIG. 12, the transmit path may also be used to sendnon-data commands to the INIC. For example, the ATCP driver gives acontext to the INIC by filling in a command buffer 330, mapping it witha packet 333 and buffer descriptor, and calling NdisSendPackets.

[0295] Given the above different types of sends, theATKProtocolSendComplete routine will perform various types of actionswhen it is called from NDIS. First it examines the reserved area of thepacket descriptor to determine what type of request has completed. Inthe case of a slow-path completion, it can simply free the mbufs,command buffer, and descriptors and return. In the case of a fast-pathcompletion, it notifies the TCP fast-path routines of the completion soTCP can in turn complete the client's IRP. Similarly, when a non-datacommand buffer completes, TCP will again be notified that the commandsent to the INIC has completed.

[0296] The only query operation currently done by the ATCP driver is aquery to obtain stats. This is done by the function ATKUpdatelnicStats() in file atkinfo.c. Currently, the ATCP driver recognizes four statusindications from the lower INIC driver. These are handled by thefunction ATKStatus( ), in proto.c. An NDIS_STATUS_MEDIA_DISCONNECTstatus indication is received if the INIC driver detects that the linkstatus on an interface is down. We simply mark our corresponding IFACEstructure as “down”. An NDIS_STATUS_MEDIA_CONNECT status indication isreceived when a previously down link status changes back to “up”. Wemark the corresponding IFACE as “up”, and also do a gratuitous ARP toadvertise it. An NDIS_STATUS_RESET_START status indication is receivedwhen the INIC driver has decided to issue a reset to the INIC. Thisreset will destroy any TCP or other contexts on the affected interface(we have no way to recover a context from a dead INIC): so we call thefunction ATKResetFlush( ), in file atkfastpath.c, to abort anyconnections on the indicated interface. The interface is also markeddown. An NDIS_STATUS_RESET_END status indication is received when theINIC driver has reloaded and restarted an INIC after a reset. We markthe corresponding IFACE as “up.”

[0297] We may not initiate INIC resets from the ATCP driver. Instead, asnoted in above, we may respond to reset status indications from the INICdriver below the ATCP driver. Similarly, we do not initiate any HALToperations from the ATCP driver.

[0298] In a first embodiment, the INIC handles only simple-casein-sequence data transfer operations on a TCP connection. These ofcourse constitute the large majority of CPU cycles consumed by TCPprocessing in a conventional driver. There are other complexities of theTCP protocol that are still in this embodiment handled by host driversoftware: connection setup and breakdown; out-of-order data, nonstandardflags etc. The NT OS contains a fully functional TCP/IP driver, and abetter solution is to enhance this so that it is able to detect our INICand take advantage of it by “handing off” data-path processing whereappropriate. Unfortunately, we do not have access or permission tomodify NT source. Thus the optimal solution above, whilestraightforward, is not implemented immediately. We thus provide our owncustom driver software on the host for those parts of TCP processingwhich are not handled by the INIC.

[0299] This presented a challenge: The NT network driver framework doesmake provision for multiple types of protocol driver; but it does noteasily allow for multiple instances of drivers handling the sameprotocol. For example, there are no “hooks” into the Microsoft TCP/IPdriver which would allow for routing of IP packets between our driver(handling our INICs) and the Microsoft driver (handling other NICs). Oursolution to this was to retain the Microsoft driver for all non-TCPnetwork processing (even for traffic on our INICs), but to invisibly“steal” TCP traffic on our connections and handle it via our own(BSD-derived) driver. The Microsoft TCP/IP driver is unaware of TCPconnections on interfaces we handle.

[0300] The network “bottom end” of this plural path processing wasdescribed earlier in the document. In this section we will discuss the“top end”—the TDI interface to higher-level NT network client software.We make use of an NT facility called a filter driver (see FIG. 7). NTallows a special type of driver (“filter driver”) to attach itself “ontop” of another driver in the system. The NT I/O manager then arrangesthat all requests directed to the attached driver are sent instead tothe filter driver; this diversion is invisible to the rest of thesystem. The filter driver may then either handle these requests itself,or pass them down to the underlying driver that the filter driver isattached to. Provided the filter driver completely replicates the(externally visible) behavior of the underlying driver when it handlesrequests itself, the existence of the filter driver is invisible tohigher-level software.

[0301] Our filter driver attaches on top of the Microsoft TCP/IP driver.This gives us the basic mechanism whereby we can intercept requests forTCP operations and handle them in our driver instead of the Microsoftdriver. The functions which actually receive the request IRPs fromhigher levels are the various dispatch routines in the file atcpinit.c(this also contains the initialization code).

[0302] However, while the filter driver concept gives us a framework forwhat we wanted to achieve, there were some significant technicalproblems that were solved. The basic issue is that setting up a TCPconnection involves a sequence of several requests from higher-levelsoftware, and it is not always possible to tell, for requests early inthis sequence, whether the connection should be handled by our driver orthe Microsoft driver.

[0303] In a nutshell, this means that for many requests we storeinformation about the request in case we need it later, but also allowthe request to be passed down to the Microsoft TCP/IP driver in case theconnection ultimately turns out to be one for which that driver shouldhandle.

[0304] Let us look at this in more detail, which will involve someexamination of the TDI interface. The TDI interface is the NT interfaceinto the top end of NT network protocol drivers. Higher-level TDI clientsoftware which requires services from a protocol driver proceeds bycreating various types of NT FILE_OBJECTs, and then making variousDEVICE_IO_CONTROL requests on these FILE_OBJECTs.

[0305] There are two types of FILE_OBJECT of interest here. Local IPaddress/port combinations are represented by ADDRESS objects, and TCPconnections are represented by CONNECTION objects. The steps involved insetting up a TCP connection (from the “active”, client, side) are: 1)Create an ADDRESS object, 2) Create a CONNECTION object, 3) Issue aTDI_ASSOCIATE_ADDRESS IO-control to associate the CONNECTION object withthe ADDRESS object, 4) Issue a TDI_CONNECT IO-control on the CONNECTIONobject, specifying the remote address and port for the connection.

[0306] Initial thoughts were that handling this would bestraightforward: we would tell, on the basis of the address given whencreating the ADDRESS object, whether the connection is for one of ourinterfaces or not. After which, it would be easy to arrange for handlingentirely by our code, or entirely by the Microsoft code: we would simplyexamine the ADDRESS object to see if it was “one of ours” or not. Therewere two main difficulties, however.

[0307] First, when the CONNECTION object is created, no address isspecified: it acquires a local address only later when theTDI_ASSOCIATE_ADDRESS is done. Also, when a CONNECTION object iscreated, the caller supplies an opaque “context cookie” which will beneeded for later communications with that caller. Storage of this cookieis the responsibility of the protocol driver: it is not directlyderivable just by examination of the CONNECTION object itself. If wesimply passed the “create” call down to the Microsoft TCP/IP driver, wewould have no way of obtaining this cookie later, if it turns out thatwe need to handle the connection.

[0308] Therefore, for every CONNECTION object which is created, we mustallocate a structure to keep track of information about it, and storethis structure in a hash table keyed by the address of the CONNECTIONobject itself, so that we can locate it if we later need to processrequests on this object. We refer to this as a “shadow” object: itreplicates information about the object stored in the Microsoft driver.We also pass the create request down to the Microsoft driver too, toallow it to set up its own administrative information about the object.

[0309] A second major difficulty arises with ADDRESS objects. These areoften created with the TCP/IP “wildcard” address (all zeros); the actuallocal address is assigned only later during connection setup (by theprotocol driver itself.) A “wildcard” address does not allow us todetermine whether connections that will be associated with this ADDRESSobject should be handled by our driver or the Microsoft one. Also, aswith CONNECTION objects, there is “opaque” data associated with ADDRESSobjects that cannot be derived just from examination of the objectitself. (In this case addresses of callback functions set on the objectby TDI_SET_EVENT IO-controls.)

[0310] Thus, as in the CONNECTION object case, we create a “shadow”object for each ADDRESS object that is created with a wildcard address.In this we store information (principally addresses of callbackfunctions) which we will need if we are handling connections onCONNECTION objects associated with this ADDRESS object. We store similarinformation, for any ADDRESS object that is explicitly for one of ourinterface addresses, as it is convenient to use the same structure forboth cases. With this concept of “shadow” objects in place, let usrevisit the steps involved in setting up a connection, and look at theprocessing performed in the ATCP driver.

[0311] For an outgoing or “active” connection setup, the TDI clientfirst makes a call to create the ADDRESS object. Assuming that this is a“wildcard” address, we create a “shadow” object before passing the calldown to the Microsoft driver.

[0312] The next step (omitted in the earlier list for brevity) isnormally that the client makes a number of TDI_SET_EVENT IO-controlcalls to associate various callback functions with the ADDRESS object.These are functions that should be called to notify the TDI client whencertain events (such as arrival of data, disconnection requests, etc.)occur. We store these callback function pointers in our “shadow” addressobject, before passing the call down to the Microsoft driver.

[0313] Next, the TDI client makes a call to create a CONNECTION object.Again, we create our “shadow” of this object.

[0314] Next, the client issues the TDI_ASSOCIATE_ADDRESS IO-control tobind the CONNECTION object to the ADDRESS object. We note theassociation in our “shadow” objects, and also pass the call down to theMicrosoft driver.

[0315] Finally the TDI client issues a TDI_CONNECT IO-control on theCONNECTION object, specifying the remote IP address (and port) for thedesired connection. At this point, we examine our routing tables todetermine if this connection should be handled by one of our interfaces,or by some other NIC. If it is ours, we mark the CONNECTION object as“one of ours” for future reference (using an opaque field that NTFILE_OBJECTS provide for driver use.) We then proceed with connectionsetup and handling in our driver, using information stored in our“shadow” objects.

[0316] The Microsoft driver does not see the connection request or anysubsequent traffic on the connection.

[0317] If the connection request is NOT for one of our interfaces, wepass it down to the Microsoft driver. Note, however, that we can notsimply discard our “shadow” objects at this point. The TDI interfaceallows re-use of CONNECTION objects: on termination of a connection, itis legal for the TDI client to dissociate the CONNECTION object from itscurrent ADDRESS object, re-associate it with another, and use it foranother connection. Thus our “shadow” objects must be retained for thelifetime of the NT_FILE OBJECTS: a subsequent connection could turn outto be via one of our interfaces.

[0318] For an incoming or “passive” connection setup, NT allows at leasttwo ways of doing things. There are explicit TDI_LISTEN and TDI_ACCEPTcalls defined in the TDI spec. There is also a callback mechanismwhereby a TDI client can arrange to be called when an incomingconnection request for a given port/address is seen.

[0319] In point of fact, no existing TDI clients appear to use theexplicit TDI_LISTEN and TDI_ACCEPT calls, and we are not handling themin the ATCP driver. All incoming connections are made via the callbackmechanism.

[0320] Initial steps are similar to active connection handling. The TDIclient creates an ADDRESS object, then creates one or more CONNECTIONobjects and associates them with it. It also makes TDI_SET_EVENT callson the address object to set up handlers for data input, disconnection,errors, etc., and in this case, it also registers one more handler forconnection requests. All of these creations and associations are“shadowed” in the ATCP driver, as in the active connection case.

[0321] Next, recall that the INIC driver knows about the IP addresses ofour interfaces, and filters incoming IP packets based on thisinformation. So any connection requests which we see in the ATCP driverare known to be for our interfaces.

[0322] Now we process analogously to the Microsoft TCP driver: for anincoming connection request (TCP SYN), we look for a “best match”address object. All our shadow ADDRESS objects are kept in a tablehashed by port for this purpose. An address object matches if its portnumber matches the destination port in the packet; a match of both portand IP address takes precedence over a match of port only.

[0323] Assuming a suitable ADDRESS object is found, we call theconnection handler function which the TDI client registered in thatobject with information about the connection request (most importantly,the remote address and port.) If the TDI client which created thatADDRESS object is prepared to handle this connection request, itresponds with a TDI_CONNECT IRP, plus a “connection cookie” which shouldcorrespond to the “context cookie” of one of the CONNECTION objectsassociated with this ADDRESS object. We locate this CONNECTION object,mark it as “one of ours”, and proceed with BSD code TCP protocolprocessing to establish the connection.

[0324] As in the active connection case, all activity on this connectionis handled by the ATCP driver; the Microsoft TCP driver knows nothingabout it. Conversely, incoming connection requests for interfaceaddresses other than INIC addresses are filtered out at the INIC level;the ATCP driver never sees such connections or any traffic on them.

[0325] In some cases when an ADDRESS object is created, an explicit portnumber is specified by the TDI client. This is typically the case forservices (such as NETBIOS or FITP) which are preparing to respond torequests on well-known, assigned ports.

[0326] In other cases, however, a port number of zero is given. In thatcase, the TCP protocol driver is required to assign a port number. Onceagain we run into the issue that, at the time an ADDRESS object iscreated, we don't know if that address object is going to be used forconnections on our interfaces or others. In particular, there areproblems in the case of an ADDRESS object created with both port andaddress as wildcards. If we assigned an arbitrary ephemeral port for theATCP “shadow” object, we would run into fatal problems with WINSOCKapplications such as WINS which create an ADDRESS object with nospecified port, and then query the address object to find what port wasassigned by the protocol driver. We would not know, in the case of awildcard ADDRESS object, which port number to return for the query:ours, or the one assigned by the Microsoft driver.

[0327] Thus, we have to ensure that there is a single, consistent,port-number space. To do so, we must always allow the Microsoft driverto create its ADDRESS object (and hence assign its port), and then catchthe completion of the Microsoft create operation. At that point, weissue a TDI_QUERY_INFORMATION request on the object to obtain the portnumber that was assigned by the Microsoft driver, and plug it into our“shadow” ADDRESS object.

[0328] A consequence of this is that, even in the case of an ADDRESSobject which is explicitly for one of our interfaces, we still allow theMicrosoft driver to create a corresponding ADDRESS object if no portnumber was specified, in order to ensure a single consistent port-numberspace.

[0329] The structures used for ATCP ADDRESS and CONNECTION objects aredefined in the file obmgr.h.

[0330] Most of the code for dealing with our shadow objects is in thefile obmgr.c; this contains functions which handle object creation,cleanup and close, as well as the TDI_ASSOCIATE_ADDRESS,TDI_DISSOCIATE_ADDRESS and TDI_SET_EVENT_HANDLER IO-controls.

[0331] Note that we catch the completion of most of the requests ofinterest, and in fact much of our processing is done in our completionhandlers. In general, we want to proceed with our processing only afterwe know that the Microsoft driver has successfully completed.

[0332] Adapting the BSD TCP code to NT has been accomplished first byfairly straightforward resolution of clashes between BSD and Microsoftdefinitions, winnowing down the BSD system header files to a minimum,and converting requests for various common OS resources (memoryallocation, copying, etc.) from BSD to NT services.

[0333] Areas where substantial redesign was needed to change from thesocket paradigm to the TDI interface are discussed in more detail below.

[0334] For BSD Data Structures we have, as noted earlier, attempted tokeep the code as close to the BSD base as is possible. Thus for eachconnection, we have a socket structure, an in_pcb structure, and a tcpcbstructure. These are defined in the usual BSD headers: socketvar.h,in_pcb.h, and tcp_var.h respectively (though tcp_var.h has moved to acommon include directory, since it is also used by INIC code.)

[0335] Each connection also has an ATCP connection object (ATCONN,defined in obmgr.h.) This means there are a total of four linked datastructures for each connection: this is unpleasantly unwieldy, and wouldcertainly not have been the approach had we been designing from scratch.

[0336] The BSD structures have changed somewhat from their originalforms. The inpcb structure has changed to use the Microsoft LIST_ENTRYdefinitions for queueing; and now contains link fields for a new list ofconnections which are being handled by the ATCP driver as opposed to theINIC. The tcpcb fields have been substantially rearranged because aportion of the tcpcb structure is shared directly with the INIC (DMA'din and out when connections are migrated), and some fields have beenreduced from 4 to 2 bytes to conserve memory on the INIC. And the socketstructure has acquired many new fields, mostly concerned with fastpathprocessing; it has also lost a number of fields concerned with LISTENingsocket queues since the TDI passive connection mechanism is radicallydifferent.

[0337] Note that the socket structure exists primarily for compatibilitywith function calls made by BSD TCP code. It has also become arepository for a number of new ATCP per-connection fields, but theirlocation here is rather arbitrary, as they could equally well have beenplaced in the inpcb or tcpcb structures. Its use differs considerablyfrom a BSD socket. In the ATCP driver, a socket structure is allocatedonly when a connection is set up and has no existence apart from TCPconnections. Also unlike BSD, there is no correspondence between thiskernel-level socket structure and any user-level socket. The “sockets”provided by the Microsoft WINSOCK library are an entirely separateabstraction, which mimic the user-level behavior of BSD sockets bycreating and manipulating ADDRESS and CONNECTION file objects in alibrary layer above the TDI interface.

[0338] The mbuf structure has also changed quite considerably from BSD.It is now defined in atkmbuf.h. There are no “small” (128 byte) mbufs inthe ATCP driver. ATCP mbufs are purely headers, whose m_data fieldspoint to actual data blocks (of various kinds) elsewhere. In fact, ATCPmbufs fall into 4 categories: 1) T_NDIS mbufs, which map NDIS buffersfrom the lower-level INIC driver, 2) MT_HEADER mbufs, which point to 2Khost buffers, similar to BSD's “cluster” mbufs, 3) MT_HOSTMDL mbufswhich map MDLs from a TDI_SEND, 4) MT_HCMD mbufs which map outgoing NDIScommand buffers.

[0339] The m_hdr and pkthdr components of the mbuf struct have beenretained (though all mbufs now contain a pkthdr), but many new fieldshave also been added, on a somewhat ad-hoc basis as they were needed.

[0340] For Operation Completion, the BSD TCP code uses a traditionalUNIX approach. All processing occurs in the (kernel) context of theprocess owning the socket for the connection. Each request (forconnection, data output, etc.) executes in the process context until itreaches a point where it is necessary to wait for resources or activity.At that point the process sleeps. When it is later woken (by aninterrupt, timer, etc.), processing resumes, still in the processcontext.

[0341] As we have noted elsewhere, the NT paradigm is more asynchronous.A request is initiated by receipt of an IRP, but once processing hasbeen started and the IRP is placed into a pending state, the initiatingthread is free to go about other business. At the point where we want tocomplete the IRP, we no longer have any reference to the originatingthread, and indeed, that thread may not even be explicitly waiting forthe particular completion. The question arises, therefore: in whatcontext will IRP completions run in the ATCP driver?

[0342] The solution we have chosen is a DPC. This is an NT kernelfacility that allows a call to a function to be scheduled (to run in anarbitrary thread context) as soon as the processor on which the DPCrequest was made becomes free. When we create our CONNECTION objects,each one has a DPC object initialized in it. Then, the BSD “wakeup”functions (sorwakeup, sowwakeup, soisconnected, etc.) are reimplementedas code which schedules a DPC on that connection (and also sets flagbits to indicate which event has occurred.)

[0343] The actual function which is run by the connection DPC isATKConnDpc; the code for this is in atksocket.c. This DPC function iscentral to the operation of the ATCP driver: most IRP completions, aswell as slow-path data indications and delivery, run in this DPCcontext.

[0344] In a BSD system, Active Connection Setup starts with creating asocket. In NT, however, it starts with creating ADDRESS and CONNECTIONobjects, as described in section 10.2.

[0345] The final step is a TDI_CONNECT IO-control on the connectionobject. This results in a call to the function ATKConnect( ), in thefile atktdi.c. After some initial checks, this calls the functionATKSoCreate (in file atksocket.c) which allocates socket, inpcb andtcpcb structures for the connection and links them together in the waysexpected by the BSD code (and also links this assemblage to theconnection object.)

[0346] At this point, we now have data structures in a form which isusable by the BSD TCP code. We simply call tcp_usrreq( ) withPRU_CONNECT to cause the connection to be initiated, and pend theTDI_CONNECT IRP, saving a pointer to it in the connection object. TheBSD code then proceeds essentially as it would in a BSD system, and oncethe connection is established, it calls soisconnected( ). In the ATCPworld, this translates to a function which schedules a DPC on theconnection; when the ATKConnDpc( ) function runs, it completes theTDI_CONNECT IRP.

[0347] For Passive Connection Setup, there are no “listening” sockets inthe NT world. Large sections of tcp_input( ) concerned with listeningsockets are #ifdef'd out.

[0348] Instead, when we detect an incoming SYN segment in tcp_input( ),we call ATKPassiveConnect( ), which is located in the file atktdi.c.This function implements the callup described above to locate aconnection object to use for the connection. Assuming one is found, wecall ATKSoCreate, which as in the active connection case allocatessocket, inpcb and tcpcb structures for the connection and links them upas required by the BSD code. We then save the returned TDI_CONNECT IRPin our connection object, and return to tcp_input( ). Processing thencontinues as if the newly-created socket were one of the “spawned”sockets from a BSD “listening” socket, and once the connection isestablished, the BSD code calls soisconnected( ).which schedules a DPCwhich completes the IRP.

[0349] Disconnection in the NT world is not signaled by a ‘close’ on adescriptor, instead there is an explicit TDI_DISCONNECT IO-control.

[0350] The TDI_DISCONNECT call results in a call to ATKDisConnect (infile atktdi.c.) Handling is somewhat similar to that of activeconnection setup: we pend the IRP, save a pointer to it in ourconnection object, and call tcp_usrreq( ) to initiate the disconnectionhandshake.

[0351] Note that if the context is currently on the INIC (i.e. we are infastpath state), we must flush the context from the INIC beforeproceeding with disconnection. In that case we note the disconnection insocket flags and issue a flush but do not call the BSD code here. Thedisconnection will be done when the flush completes.

[0352] Once the BSD code has completed the disconnection handshake, itcalls soisdisconnected( ). In the ATCP driver this translates to ascheduling of the connection DPC; the DPC function completes any pendedTDI_DISCONNECT IRP.

[0353] A further NT wrinkle here is that TDI clients register adisconnection handler function for connections, and we normally need tocall this, as well as completing any TDI_DISCONNECT IRP, when closing aconnection. We also need to call the disconnection notify function whenthe close originates from the other side: in that case the tcp_inputcode calls socantrcvmore( ) which again translates to a scheduling ofthe connection DPC with appropriate flags.

[0354] The notification is done by ATKNotifyDisConnection (in fileatksocket.c); the determination of whether, and with what flags, weshould call the disconnection notify function, is made by a series oftests at the start of this function.

[0355] The next few paragraphs describe slow-path output. Data output ona connection is initiated by a TDI_SEND request on the CONNECTIONobject; the request IRP points to an MDL describing the data to be sent.The request results in a call to ATKSend (in file atktdi.c.) This locksthe connection, and after some initial checks calls ATKMapMdlToMbuf,located in the file atkmbuf.c. The latter allocates an ATCP mbuf to mapthe request; a pointer to the IRP is saved in a field in the mbuf. Notethat, unlike BSD, we do NOT copy data from the request; we simply mapthe request MDL with an mbuf header. Also, there is no notion in ATCP ofa “watermark”: any TDI_SEND request is always accepted and queued. TheTDI rule is that the TDI_SEND IRP is not completed until the data fromit is actually acknowledged by the peer, so throttling of send requestsis accomplished in NT by deferring their completion, rather thanblocking the sender as in BSD.

[0356] The mbuf is then queued on to the socket send buffer, and we calltcp_usrreq( ) with PRU_SEND to cause the BSD TCP code to actually sendthe data (this in fact results in a call to tcp_output.) The connectionis then unlocked.

[0357] The usual checks are made in tcp_output to determine whether aframe can be sent. If possible, we build a buffer containing MAC, IP andTCP headers, followed by the data. Details of this differ somewhat fromregular BSD. The mbuf we use for output is an MT_HEADER mbuf, whichpoints to a 2K buffer in host memory. This is always enough to containall the protocol headers plus a maximum-sized amount of payload, so weconstruct the entire packet in a single mbuf. We allow space at thefront of the buffer for the protocol headers, and then callm_copymdldata( ), located in atkmbuf.c, to copy data from the TDI_SENDMDLs mapped by mbufs queued on the socket send buffer into the packet weare constructing. The mbuf containing the output packet is then passeddown to ip_output( ) as usual.

[0358] Later, when data has been ACK'd by the peer, there is a call fromtcp_input( ) to sbdrop( ) on the socket send buffer. The sbdrop code (inatksocket.c) performs processing essentially similar to vanilla BSD code(though it has been somewhat simplified): it adjusts m_data and m_lenfields in the mbufs chain it is operating on, and if any mbufs areentirely consumed, it calls m_free( ) to release them.

[0359] The m_free( ) function (in file atkmbuf.c) has been modified torecognize the new ATCP mbuf types: when it detects that the mbuf is onewhich maps a TDI_SEND MDL, it schedules a DPC to cause the associatedTDI_SEND IRP (which we saved in the mbuf before queueing it on thesocket send buffer) to be completed.

[0360] The next few paragraphs describe slow-path input. Processing islargely unchanged from BSD up to the point where the tcp_input( ) codequeues the mbuf on to the socket receive buffer with sbappend( ), andcalls sorwakeup( ).

[0361] At that point things become very different. In NT there is noprocess sleeping on the socket receive buffer to be woken up and copyout the data. Instead, the sorwakeup( ) call translates in ATCP termsinto a scheduling of the connection DPC; when this runs, it callsATKPresentData (in file atktdi.c) to deal with the data which has beenappended on to the socket.

[0362] The basic approach is that if we currently have an MDL we copythe data into it and complete it if possible. If we don't have an MDL,or have data left over after copying into the one we completed, we willindicate data, unless we're in a state where we have already indicatedand are expecting an MDL from a TDI_RECEIVE shortly. The ATKPresentData() function is also cognizant of fastpath, and will call ATKDataRequest(in file atkfastpath.c) to hand out MDLs to the INIC when appropriate.

[0363] Data which has been consumed, either by copying into an MDL or bybeing taken by an indication, is dropped from the socket receive bufferwith sbdrop( ). This calls m_free( ) once an mbuf has been completelyconsumed. The m_free function has been enhanced to know about the ATCPflavors of mbufs; it detects that this receive mbuf is actually onemapping NDIS buffers, and returns them to NDIS.

[0364] The fast-path data pathways and connection handout and flush werediscussed conceptually earlier, so we will now simply identify theactual code which implements these functions, adding a few notes as wego. Most of the fastpath code is in file atkfastpath.c; all functionsmentioned in this section are in this source file unless noted otherwiseor earlier identified.

[0365] Fast-path input frames are identified as such in ATKReceiveDpc(file proto.c), and handed to ATKFastInput( ). There, if it is a dataframe or header, we simply queue it on the socket receive buffer andcall ATKPresentData( ); as noted in the previous subsection, this knowsabout fastpath and is prepared to hand out MDLs to the INIC ifappropriate. The completion of fastpath receive MDLs is handled byATKFastReceiveDone( ).

[0366] Fast-path output originates in ATKSend; there, if the connectionis in fastpath state we do not do the slow-path processing described insection 11.6. Instead we map the MDL with a data request structure(ATKDR, defined in socketvar.h), save the IRP in that request, queue therequest on the socket, and call ATKFastSendStartIo (file atkfastpath.c.)If there are currently less than the maximum allowed outstanding sendrequests active on the INIC, this calls ATKDataRequest( ) to hand thesend MDL out to the INIC.

[0367] Completion of fastpath send requests is handled inATKFastSendDone( ).

[0368] The decision to hand a connection out to the INIC is made in theubiquitous DPC function ATKConnDpc( ), either immediately when aconnection is set up, or later when the connection is determined to bein a suitably quiescent state. This is a natural place to control thehandout, since the DPC function is centrally involved in almost any dataactivity or state transition which affects the connection. The initialhandout message is sent by ATKStartMigration( ). When the NULL interlockframe arrives it is handled by ATKHasProvisionalContext( ); this doessome checks to ensure that migration should still proceed, and if so,calls ATKCompleteMigration( ) to send the second-half handout command.Completion of this is handled by ATKCompleteMigrationDone( ), which doesa few more checks and then sets the fastpath state of the connection to“established”. There is an ordered set of fastpath states, ratheranalogous to the TCP finite-state machine states, defined insocketvar.h: SO_FPNONE to SO_PFCLEANUP.

[0369] Origination of a flush from the host side is done by the functionATKFlushContext( ) which simply sends a flush command identifying thecontext to flush. The final cleanup is done in ATKFastPathCleanup( );this may be called from ATKFastInput( ) on receiving a “flush” frame, orfrom either of ATKFastReceiveDone( ) or ATKFastSendDone( ) on receivingan error completion. (Recall from above that the cleanup must have seencompletions of all outstanding data requests, plus the flush frame,before it can proceed.

[0370] The BSD code contains many IOCTL handlers for obtainingstatistics. However, these have no direct correspondence to the NTstatistics queries, and additionally, we must deal with the fact thatthere are two parallel protocol stacks. In many cases, the overallstatistics being requested are made up of components from both stacks.Therefore, we do not use any of the BSD IOCTL handler code.

[0371] Instead we arrange to catch completion of the various NTstatistics queries, which are IOCTL_TCP_QUERY_INFORMATION_EX requests onCONTROL FILE_OBJECTS, so that we can merge information from our driverwith that returned from the Microsoft driver.

[0372] The functions for doing this are in atkinfo.c. Note that forcertain statistics, only the INIC has the exact values, since itconsumes protocol headers internally for fastpath connections. Thereforein order to obtain the ATCP information to merge with the informationfrom the Microsoft driver, we need to query the INIC. AnAlacritech-specific OID_INIC_GET_STATS is defined for this purpose, andused in ATKUpdateInicStats( ). We notice from tracing that NT isastoundingly profligate and inefficient in its use of stats queries (anetstat invocation, for example, may result in literally thousands ofrepeated queries!), so we keep a timestamp of last query and repeat theINIC query only after a reasonable time has elapsed since the previousone.

[0373] In most places where a structure needs to be allocated on theATCP driver for memory allocation, we are just calling the basic NTExAllocatePool( ) function. We don't at this point have a good feel forhow efficient (or otherwise) the NT kernel memory allocation code is: ifprofiling later shows that it is worth while, we could adopt theapproach of keeping our own (hopefully more efficient) freelists of ourcommonly-used structures.

[0374] This might be particularly relevant if connection setup overheadproves to be an issue, since three separate structures (socket, inpcband tcpcb) need to be allocated for each connection. Rather than doingthree separate allocations, we could keep a free pool of groups ofthese, already linked appropriately.

[0375] We have taken the pragmatic approach of implementing only thefunctionality that we have actually observed to be used, in tracing andextensive testing. However, there are a number of other features whichmay be derived from the TDI spec or inferred from the Microsoft TCP codewhich have never been observed to be used, and we have omitted them forsimplicity. These include: Out-of-band data, TDI_LISTEN and TDI_ACCEPTcalls, IOCTLs for setting interfaces up and down, IOCTLs for settingsecurity information (although registry keys for security features areimplemented on a separate pathway), and a number of “hidden” registryparameter keys.

[0376] As with conventional networking cards, the Alacritech INICemploys an associated device driver. This document describes the devicedriver used with the Microsoft Windows NT, and 9× operating systems.

[0377] Network device drivers used in Microsoft operating systemsconform to the Network Driver Interface Specification (NDIS) defined byMicrosoft. NDIS provides a set of standard entry points used forinitialization, query and set functions (IOCTLS), sending and receivingdata, and reset and shutdown. NDIS also provides a set of libraryfunctions used to interact with the operating system. These functionsinclude routines used to allocate memory, access PCI IO space, allocateand manage buffer and packet descriptors, and many other functions. AnNDIS driver must be implemented exclusively within the bounds of NDISand not make any calls to NT or 9× operating system routines directly.

[0378] An NDIS NIC driver is used as a means of communication betweenupper level protocol drivers (TCP/IP, Appletalk, IPX) and a specificnetworking device. For example, when the TCP/IP protocol driver, wishesto send an ethernet packet, the packet is passed to the NIC driver viathe standard NDIS transmit interface. The NIC driver is responsible forinteracting with its associated hardware to ensure that the packet istransmitted on the network.

[0379] As shown in FIG. 13, the INIC miniport driver 200 is implementedas a standard miniport driver is connected to the INIC 50 over the PCIbus 57. The INIC has four network connections 340 in this embodiment.

[0380] As mentioned above, we can reduce the number of interactionsbetween the INIC device driver and the INIC 50 (nicknamed Simba) bypassing multiple buffers to the INIC in a single write, and allocating aphysically contiguous chunk of memory and dividing it into severalbuffers. We also define four types of buffers. Header buffers, whichcontain information about received data as well as possibly the dataitself (if the data is small) data buffers, which are always accompaniedby a header buffer, which contain large chunks of received data, commandbuffers, which contain information about data that is to be sent, andresponse buffers, which contain information about command buffers thathave just been completed.

[0381] Header buffers are 256 bytes, data buffers are 2 k, commandbuffers are 512 bytes, and response buffers are 32 bytes. Thus, in acontiguous 4 k page, we can allocate 16 header buffers, 2 data buffers,8 command buffers, or 128 response buffers. Thus in a single write wecan pass 16 header buffers, or 2 data buffers, or 128 response buffersoff to the INIC. We choose a 4 k buffer size because that is the pagesize for NT. Theoretically, NT should allow us to allocate larger blocksof contiguous memory, but likelihood of the allocation failing increasespast the page size. We call this 4 k page a Simba Data Buffer (SDB).

[0382] Let's say that we pass 16 header buffers off to the INIC. Theseheader buffers will be returned to us as data arrives, and are likely tobe passed upstream to the ATCP driver. They will then be returned to us,out of order, at a later time at which point we can mark them as free.Before we can re-use the SDB, however, all of the buffers (header, ordata, etc) within that SDB must have been returned to us. Since ATCP canreturn them in any order we need a way of keeping track of which bufferswithin an SDB are free and which are still in use. We do this bymaintaining a 16-bit bitmask. Bits are cleared when the correspondingbuffers are handed to the INIC (all 16 for header buffers, just 2 fordata buffers), and then reset when the buffer is freed. When the bitmaskis full, the SDB can be re-used.

[0383] Note that 16 bits is not enough to manage the 128 responsebuffers. It is not necessary to keep track of the response buffers sincethey are never passed upstream. For response buffers, we just maintain acircular queue of two SDBs. When the INIC uses all of the buffers in oneresponse SDB, we pass it back to the INIC and jump to the other. Notealso that while the INIC driver also uses SDBs for command buffers,command buffers are only passed to the INIC one at a time. Furthermore,as discussed elsewhere, the ATCP driver allocates and manages its ownseparate set of command buffers.

[0384] As we've noted, we must maintain a bitmask for SDB. We need tomaintain other information about an SDB as well. This informationincludes the virtual and physical address of the SDB, linked listpointers, the type of SDB (header, data, etc), the current offset withinan SDB (next expected header/response buffer), etc. We keep all of thisinformation in a structure that we call SDBHANDLE.

[0385] We have a unique challenge in the INIC driver. Unlike other NICdrivers, the INIC driver may be receiving data that has already beenacknowledged by the INIC network adapter. This means that once data hasbeen received by the driver, it cannot be dropped. This in turn requiresthat all resources needed to receive a packet are allocated before aheader and/or data buffer is passed off to the INIC. Included in theseresources are NDIS buffer and packet descriptors. NDIS buffer and packetdescriptors are used to map a network buffer when being passed via NDIS.The packet descriptors represent a received frame, and can be made up ofmultiple physical buffers, each represented by a NDIS buffer descriptor.Note that as pointed out above, every received frame is given to us viaa header buffer, and there may or may not be an associated data bufferwith it. This means that for every header buffer given to the INIC wemust pre-allocate a packet descriptor and a buffer descriptor (since theheader buffer may be sent upstream), while for every data buffer we mustonly pre-allocate a buffer descriptor. Since these resources arepre-allocated, we need a place to store them until the header and/ordata buffers are returned to us. Again, we maintain a structure calledthe SDBDESC (SDB Descriptor) structure for every header and data buffergiven to the card. We include 16 of these structures in the SDBHANDLEstructure, one for each header buffer in an SDB (14 are not used fordata buffers).

[0386] We maintain several queues of SDBs for each adapter in thesystem. These queues are named and described as follows:

[0387] AllSDBs is a linked list of all SDBs allocated for the adapter.Used to locate and free SDBs when the driver is halted.

[0388] FreeSDBs is a linked list of SDBs which are free for use (bitmaskis 0×FFFF).

[0389] HdrQueue is a linked list of header SDBs. Used by theSimbaReceiveDpc routine described below to locate newly received frames.

[0390] CmdQueue is a list of free command buffers which can be sent,when needed, to the INIC.

[0391] RspQueue is a circular queue of SDBs that contain responsebuffers used by the INIC. Note that we do not maintain a queue of databuffer SDBs. Data buffer SDBs are allocated from the free queue andgiven directly to the INIC. They are returned to us attached to headerbuffers so we do not need to keep track of them ourselves. This isdescribed further below.

[0392] As shown in FIG. 14, in a given system, we maintain a single INICdriver 200. Associated with that INIC driver may be a number of INICcards, each of which may contain, for example, four adapters. To keeptrack of this the driver maintains a structure that represents thedriver called the SIMBA_DRIVER structure 350. The SIMBA_DRIVER structureis pointed to by the global variable SimbaDriver. Among the fields inthe SIMBA_DRIVER structure is a pointer to a linked list of SIMBA_CARDstructures (355, 357), each one representing an INIC PCI card. TheSIMBA_CARD contains information about a particular card. This includesthe state of the card (UP, DOWN, FAIL), the PCI slot number, the numberof adapters on the card, the number of adapters initialized on the card,the number of adapters halted on the card, and other information. Italso contains a 4-entry array of ADAPT structure pointers (340, 342).For each adapter on the card (there may be less than 4), an entry inthis array is filled in with a pointer to the ADAPT structure which isused to represent that particular adapter. The ADAPT structure is theprimary structure in the INIC driver and contains, among other things,the NDIS handle associated with the interface, a back pointer to thecard structure, the index of the adapter on the card, a pointer to thebase PCI address of the INIC registers, resources associated with theinterface, etc. FIG. 14 shows an implementation having four adapters(344-351) on each of two INIC cards.

[0393] Every NT driver has a DriverEntry routine. For NDIS drivers, themain purpose of the DriverEntry routine is to register all of theexpected driver entry points with NDIS. These entry points includeMiniportInitialize (called during interface initialization),MiniportSend (called when a protocol driver wishes to send a frame),MiniportISR (called when an interrupt occurs), MiniportHalt (called whenthe driver is halted), and others.

[0394] We define SimbaInitialize as the MiniportInitialize routine forthe INIC driver. The SimbaInitialize routine is called once for everyINIC adapter in the system. Recall that an INIC adapter is an interfacefound on an INIC card. Thus SimbaInitialize can be called up to fourtimes per card. The purpose of the SimbaInitialize function is toallocate and initialize the ADAPT and optionally the SIMBA_CARDstructure, allocate resources needed by the interface, and perform anyhardware initialization required to make the interface operational, asdescribed in more detail below.

[0395] The oemsetup installation script, described below, stores anumber of parameters into the registry for each INIC adapter installedin the system. These parameters include the following query registryparameters:

[0396] CardBase—This parameter serves as a unique identifier for theINIC card. This is set to the PCI slot number with the PCI bus numberOR'd into the top bits.

[0397] CardIndex—Index of the adapter on the card (0-3 for the four portINIC).

[0398] CardSize—Number of adapters on the card.

[0399] BusNumber—Bus number on which the card resides.

[0400] SlotNumber—PCI slot number of the card

[0401] FunctionNumber—PCI function number of the adapter (0-3 for thefour port INIC).

[0402] NetworkAddress—An optional, administrator defined, networkaddress.

[0403] As noted above, the SimbaInitialize routine will be called fourtimes per four-port INIC. For each time that it is called, we mustallocate an ADAPT structure. On the other hand, we must only allocate asingle SIMBA_CARD structure to represent the entire card. This is why weread the registry parameters before allocating the ADAPT and SIMBA_CARDstructures. Having read the registry parameters, we search through thelist of already-allocated SIMBA_CARD structures looking for one that hasthe same CardBase value as the adapter that we are initializing. If wefind one, we simply link our new ADAPT structure into the Adapt arrayfield of the SIMBA_CARD structure using the CardIndex parameter. If wedo not find an associated SIMBA_CARD structure, then we allocate a newone, link in our ADAPT structure, and add the new SIMBA_CARD structureto the Cards field of the SIMBA_DRIVER structure.

[0404] Before the ATCP driver can talk to the INIC card it mustconfigure the PCI configuration space registers. This involves callingthe necessary NDIS functions to read the device and function ID's (usedto verify that the information obtained from the registry is correct),read the memory base register, read the IRQ, and write the commandregister.

[0405] Note that that there is a PCI configuration space for everyadapter on a INIC card (four for a four-port card). Thus we go throughPCI configuration every time our initialization routine is called. Thereis one catch to this. While there is a configuration space header forevery adapter, the bus master bit in the command register is onlyenabled for multifunction device 0. This can pose a problem. Assume thatwe have a four-port INIC, but the administrator has removed device 0.When we initialize PCI configuration space for devices 1, 2, and 3, busmastering will not be enabled and none of the adapters will work. Wesolve this by enabling bus mastering for device 0 every time any of theinterfaces is initialized.

[0406] The next step in the INIC initialization is to allocate all theresources necessary for a single interface. This includes mapping thememory space obtained from the PCI configuration space so that we canaccess the INIC registers, allocating map registers used to obtainphysical buffer addresses, allocating non-cached shared memory for theISR and other data, allocating pools of buffer and packet descriptors,allocating spinlocks, and registering the interrupt (IRQ) obtained fromthe PCI configuration space.

[0407] Note that we do not allocate SDBs at this time. SDBs areallocated on an as-needed basis and consequently are not allocated untilthe card is initialized and we are prepared to pass buffers off to it.

[0408] At this point in the initialization process the INIC hardware isinitialized. When we begin interface initialization we check the stateof the card (contained in the SIMBA_CARD structure). If the state isdown (probably because we are the first interface on the card to beinitialized), then we must perform INIC card initialization.

[0409] The first step in initializing the card is to reset and downloadthe card. The reset is performed by writing to the reset register. Thisis a reliable hardware register, as opposed to one serviced by firmware.After reset the firmware on the card is running out of ROM. The ROMbased firmware provides very little functionality besides assisting inthe write-able control store download.

[0410] The firmware that is to be downloaded to the INIC is compiledinto the driver as a set of static character arrays. These static arraysare found in the file simbadownload.c, which is created by the objtocutility. Objtoc is an Alacritech utility used to convert metastepassembly code output to static arrays, each array representing a singlecontiguous block of firmware.

[0411] The download is performed by a series of three writes to the WCSregister on the INIC. The first write is the address to be loaded, thesecond write is the bottom four bytes of the instruction, and the thirdwrite is the top four bytes of the instruction. We simply walk througheach static array downloading the data contained in the array.

[0412] Note that the top bits of the address written in the first writeto the WCS carry special meaning. Bit 30 tells the firmware to comparethe instruction contained in the next two writes to the instructionalready contained in the specified address. This is used to ensure thatthe download completed correctly. We first download all of the code, andthen we download it all again with the bit 30 set in the address words.If the firmware discovers an error, it will place the address of the badinstruction into location zero of SRAM. After each “compare” sequence,the driver checks the location to determine if there was an error. Ifso, the driver fails the initialization. Bit 31 of the address wordtells the firmware to jump to the specified address. We set this bitafter the firmware has been successfully downloaded to start the normalINIC operation.

[0413] The INIC contains a single structure representing theconfiguration of the card. This structure typically resides in EEPROM orFLASH. The structure contains, among other things, the DRAM size of theINIC, the SRAM size of the INIC, and the MAC addresses of the adapterscontained on the INIC.

[0414] This information is fetched from the INIC by issuing a UtilityProcessor Request (UPR) to the INIC firmware (UPRs are described below).The data returned by this UPR is contained within a shared memorystructure pointed to by the SIMBA_CARD structure.

[0415] Once the INIC has been initialized, we can initialize aparticular adapter on the card. This is done as follows:

[0416] At initialization time we queue the INIC with a set of header,data and response SDBs. We also pre-allocate a set of command SDB's andanother set of free SDB's to avoid experiencing delays when we need toacquire more SDB's.

[0417] In order to configure a particular MAC interface on the INIC, wemust first obtain information about the state of the PHY We do this byissuing a Read Link Status Register (RLSR) UPR to the INIC firmware.This command completes asynchronously. When it completes, we save theinformation returned to us into the ADAPT structure. This informationincludes the link speed (10/100 mb), the “duplexivity” of the link(half/full), and the state of the link (up/down). With this information,we can configure the MAC configuration register, the MAC receiveconfiguration register, and the MAC transmit configuration register. Wealso configure the MAC address registers with either the informationreturned from the INIC Configuration UPR described above, or, if theadministrator has specified another MAC address, we use the specifiedaddress instead.

[0418] For a Device Reset, the NDIS defines two miniport driver entrypoints used to identify and reset a dead adapter. TheMiniportCheckForHang routine is called periodically to check on thehealth of the adapter. If the adapter is sick, the CheckForHang routinereturns true. Returning true causes NDIS to send a reset statusindication to the bound protocol drivers, and to also call the driver'sMiniportReset routine. The MiniportReset routine is responsible forrestoring the adapter to an operational state. If the MiniportResetroutine returns good status, the adapter is assumed to be back online,and NDIS will send a reset-complete status indication upstream.

[0419] SimbaCheckForHang is the MiniportCheckForHang routine for theINIC driver. SimbaReset is the MiniportReset routine for the INICdriver.

[0420] Some unique challenges are associated with a card reset for thepresent invention. First, as far as is known, we are the onlymultifunction network device in existence. There are other four-portcards, of course, but they are typically four individual devices behinda PCI-PCI bridge. Because our four adapters are all associated with asingle device, we cannot reset a single adapter. Yet, since theCheckForHang and Reset functions get called for each of the fouradapters on the card, if we determine that the card needs to be resetthen each of the four driver instances must recognize that a reset hastaken place and perform initialization. This poses a synchronizationproblem. The card, of course, must only be reset once. After reset, thecard must be initialized once and all four adapters must be initializedindividually. To ensure that all four instances of the driver recognizethat a reset has occurred, and to perform re-initialization, we set theadapter state in the ADAPT structure to ADAPT_RESET for each interfaceon the card. When the CheckForHang function is called for eachinterface, it will check the adapter state to see if a reset hasoccurred. If the adapter state is set to ADAPT_RESET, it returns true.

[0421] A second challenge is core dumps. Most NICs have little or nosoftware or firmware running on the card. We have a substantial amountof firmware, and like any other code, it is subject to bugs. When thecard becomes non-operational, there is a good chance that it is theresult of a firmware bug. We have interactive debuggers that can be usedinternally to diagnose the cause of a INIC crash, but there may be timeswhen it is essential that we be able to dump the state of the card afterit has crashed.

[0422] In this situation, the contents of the INIC registers, SRAM,DRAM, and possibly some queues will be dumped from the card. Since thisamounts to many megabytes worth of data, we will need to move the datain blocks from the INIC to a file. NT allows a driver to create andwrite to a file from the kernel, but it must be done at passive level.Both the CheckForHang and the Reset routines run at dispatch level.

[0423] To get around this problem, we have introduced a “dump thread”.The dump thread is a kernel thread that is started whenever a cardstructure is allocated (i.e. one thread per card). In the INIC driver,it is actually the dump thread, not that CheckForHang routine thatmonitors the state of the card. We have the dump thread do this becausewe want to be able to dump the contents of the card before a reset isinitiated. The dump thread, upon finding a card dead, will attempt toperform the dump, and then it will set the card state to CARD_DOWN andset each adapter state to ADAPT_RESET. When the CheckForHang routine foreach adapter finds the adapter state set to ADAPT_RESET, it will returntrue as described above, to begin the re-initialization process.

[0424] The MiniportShutdown routine for the INIC driver is definedSimbaShutdown. It is called at system shutdown time so that we can putthe INIC into a known state. We simply issue a reset to the INIC whenthe shutdown routine is called.

[0425] SimbaHalt is the miniport halt routine for the INIC driver. It iscalled with the driver halted. It is responsible for freeing all of theresources associated with the particular adapter that is being halted. Atrick with this routine is to keep track of which adapters on aparticular INIC card have been halted. The last adapter to be haltedmust also free resources allocated for the INIC card (the SIMBA_CARDstructure and the shared memory used to contain the INIC configuration).We keep track of which cards have been halted in the SIMBA_CARDstructure.

[0426] SimbaQueryInformation is the MiniportQueryInformation routine forthe INIC driver. SimbaSetInformation is the MiniportSetInformationroutine for the INIC driver.

[0427] At present we support all of the required OIDs in the INICdriver. We have also added the following custom OIDs:

[0428] OID_SIMBA_ADD_IPADDR—Sent down from the ATCP driver to registeran IP address with the INIC driver. The INIC driver uses these addressesby determine which way to direct incoming traffic. This is discussedfurther below.

[0429] OID_SIMBA_REMOVE_IPADDR—Used to remove an IP address added withOID_SIMBA_ADD_IPADDR.

[0430] OID_SIMBA_GET_STATS—A query from the ATCP driver to obtainstatistics maintained on the INIC adapter. This is discussed furtherbelow.

[0431] OID_SIMBA_ATK_GLOBALS—Sent down from the ATCP driver to passshared memory information. This is primarily used for tracing. This toois discussed further below.

[0432] For message transmission, we label the MiniportSendPacketsroutine for the IMC driver SimbaSendPackets. It is called with an arrayof NDIS packet descriptors, which have been passed down to us by anupper level protocol driver (ATCP, MS TCP, IPX, etc).

[0433] For each packet contained in the array of packet descriptors weperform the steps described below.

[0434] First, we check for errors. There are a number of reasons why wemay fail to send a packet. The reasons that we may fail to send a packetare as follows:

[0435] Microcode diagnostics are enabled—We provide a set of diagnosticsthat allow us to exercise the INIC microcode in a controlled loop-backenvironment. If these diagnostics are enabled, then we do not allow anyof the standard protocol routines to send data. We fail immediately bysetting the packet status to NDIS_STATUS_FAILURE.

[0436] Link or Adapter State is not up—If the Link State or the AdapterState is down, we cannot send any packets. We fail immediately bysetting the packet status to NDIS_STATUS_FAILURE.

[0437] Zero-length packet—Strictly speaking, this is not an error. If weencounter a zero length packet we complete it successfully immediately.

[0438] Insufficient map registers—We need a map register for every NDISbuffer in the packet. If we do not have enough map registers, then wecan not send the packet. We fail immediately by setting the packetstatus to NDIS_STATUS_RESOURCES.

[0439] No command buffer—If we need a command buffer and cannot allocateone we fail immediately by setting the packet status toNDIS_STATUS_RESOURCES.

[0440] The code that interacts with the INIC hardware is separated fromthe code that interacts with NDIS. The code that interacts with the INIChardware is contained in the SimbaTransmitPacket routine as a callSimbaTransmitPacket. We separate it in this manner so that the microcodediagnostics (which run outside the context of NDIS), can share the sametransmit code as the normal path.

[0441] Command buffers contain many different types of information. Forslow-path frames, for example, command buffers contain information aboutthe address and length of the frame to be sent. Command buffers may alsobe used to hand a context from the ATCP driver out to the INIC, or toforce a flush of a context from the INIC. For these and other purposes,the ATCP driver needs to be able to set the command buffer up itself.Thus, command buffers may be allocated in two areas. Any calls toSimbaSendPackets from the ATCP driver contain an ATCP allocated commandbuffer. Any calls from other drivers, such as MS TCP, just contain rawdata (a network frame). For the calls that already contain a commandbuffer, we must simply pass the command buffer off to the INIC. Forother calls, we must allocate our own command buffer and configure itappropriately.

[0442] It is thus important to identify whether or not a packet is anormal frame or, as shown in FIG. 15, the packet 360 contains an ATCPcommand buffer 362. Our solution to this is in the ATCP driver weprepend an ethernet header 366 to the command buffer. This ethernetheader is located in a separate chunk of memory (with a separate NDISbuffer descriptor) and contains an ethernet type field of 0×666. Thisvalue was chosen not only because of its spooky nature, but also becauseit is too large to be an 802.3 length, and too small to be a validethernet type field. It is a value that we never expect to see handed tous in a frame from MS TCP, IPX, Appletalk, or any other protocol driver.

[0443] Sending command buffers that have been given to the INIC driverby the ATCP driver is relatively simple. The IMC driver maps the commandbuffer to obtain the command buffer's physical address, flushes thecommand buffer and hands it to the appropriate transmit queue on theINIC.

[0444] Several types of commands may be sent to the receive processor ofthe INIC instead of the transmit processor. These commands include therelease context command (IHCMD_RLS_CTXT) and the receive MDL command(IHCMD_RCV_MDL). The INIC driver examines the command buffer and if thecommand is one of these types, hands the command buffer to the receiveprocessor.

[0445] Note that the INIC driver does not reference any fields in thecommand buffer after it has been flushed.

[0446] As illustrated in FIG. 16, normal frames can contain any numberof buffers with many different types of data such as buffer 1 370 andbuffer 2 371. When the INIC driver receives a normal frame it firstallocates and initializes a command buffer 373 of its own. The INICdriver obtains this from the CmdQueue in the ADAPT structure. It thenmaps every buffer descriptor attached to the packet to obtain thephysical address of the buffer, and then fills in the command bufferwith these physical addresses, e.g. buffer descriptors 374 and 375 forframes 376 and 377.

[0447] The INIC driver also flushes each buffer associated with thepacket to maintain cache coherency. After we have filled the commandbuffer in with the complete list of buffers, we must then map and flushthe command buffer itself and hand the physical address of the commandbuffer off to the INIC.

[0448] After we have sent all of the packets in the packet array, wecheck to see if we have exhausted any of the command SDBs. If so weattempt to allocate replacement SDBs and requeue them to the CmdSDBqueue.

[0449] After a command issued to the INIC has completed, the resourcesheld by the command must be freed and the corresponding send, whichinitiated the command, must be completed. This is performed in theSimbaXmtDpc routine.

[0450] As described above, commands are completed by the INIC by fillingin a response buffer. The reason that we do this instead of simplysetting a completion flag in the command buffer is because commands canbe completed out of order. Some commands, like one to transmit 64 k ofSMB data, will take much longer than a command to transmit 100 bytes ofdata.

[0451] The command buffer contains a “HostHandle” field, which is filledin with the virtual address of the command buffer. When a commandcompletes, the INIC firmware puts this address into the response buffer.

[0452] Response buffers are returned to us in order, so the first thingthat the SimbaXmtDpc routine does is to locate the next expectedresponse buffer. If the status indicates that it has been filled in bythe INIC, we locate the completed command buffer from the HostHandlefield.

[0453] At the end of the command buffer, we keep a bunch of informationthat is not passed to the IMC. Among this information is the list of mapregisters used to obtain physical buffer addresses. We use this list tofree the map registers.

[0454] In the Transmit description above two types of sends arementioned, one in which the ATCP driver allocates a command buffer, andanother in which the INIC driver allocates a command buffer. Clearly, ifthe INIC driver allocated the command buffer, the INIC driver must alsofree it, yet if the ATCP driver allocated it, the INIC driver must not.We determine this by saving a pointer to the SDBHANDLE at the end of thecommand buffer. If it is an ATCP driver allocated command buffer, therewill be no SDBHANDLE set in the psdbh field of the command buffer.

[0455] NDIS defines two routines used in interrupt handling. The firstis the MiniportISR routine. It is called at interrupt level and itspurpose is to determine if the interrupt is associated with its deviceand if so, mask the interrupt and tell NDIS to schedule theMiniportHandleInterrupt routine. The MiniportHandleInterrupt routineruns at DPC level and performs the bulk of the interrupt processing.

[0456] SimbaISR is the MiniportISR routine for the INIC driver.SimbaHandleInterrupt is the MiniportHandleInterrupt routine for the INICdriver.

[0457] Note that most PCI devices maintain an interrupt status registeron the card. When an interrupt occurs, the driver must read the value ofthe ISR from PCI. Since reading data from the PCI bus is an expensiveoperation, we sought to optimize this by putting interrupt status in ahost-memory based interrupt status “register”. This memory-based ISR iscontained in the non-cached shared memory region allocated perinterface.

[0458] There are some concerns however when using a memory-based ISR.Race conditions can occur when the host driver is clearing status, whilethe INIC card is writing status. To keep this from happening, we haveintroduced a strict protocol. The INIC is not allowed to write to statusto the memory-based ISR until the driver has responded to previouslywritten status.

[0459] The SimbaISR routine first checks its memory-based ISR to see ifany events are set. If not it tells NDIS that it does not own theinterrupt. Otherwise, it sets the contents of the memory-based ISRaside, zeros the memory-based ISR and masks interrupts from the INIC.Note that even though we have masked interrupts, our ISR routine may getcalled again as the result of an interrupt being generated by anotherdevice that shares the same interrupt line. For this reason, we zero thememory-based ISR to prevent us from getting confused.

[0460] The SimbaHandleInterrupt routine checks every possible bit of theinterrupt status that we set aside in SimbaISR, and respondsappropriately. This includes calling the SimbaRcvDpc routine in the caseof a receive event, SimbaXmtDpc in the case of a command completionevent, etc.

[0461] After all of the events have been processed, we clear the eventson the INIC by writing to the interrupt status response register. Thiswill clear the way for the INIC to send us new status. We then alsounmask the interrupts. Note that we must not unmask the interrupts untilwe write to the interrupt status response register. Otherwise, the INICwill give us an interrupt for the events that it has already sent to us.

[0462] Receive data is passed from the INIC to the host by filling in aheader buffer. The header buffer contains information about the data,such as the length. If the data is small enough, the header buffer alsocontains the data itself. Otherwise, the data is contained in acorresponding data buffer. If the data resides in a data buffer, theheader buffer will contain a pointer to the SDBHANDLE structureassociated with the data buffer. Furthermore, the offset of the bufferwithin the SDB is placed in the bottom bits of the pointer to theSDBHANDLE structure.

[0463]FIG. 17 shows an example of a receive header 400 and data buffer402. In this example, the buffer field 404 of the header buffer 406contains the address of the data SDBHANDLE 408 structure (0×1000) withthe bottom bit set to indicate that the data buffer is at offset 1within the two part data SDB.

[0464] After the INIC fills in the header, and possibly data buffer 411,it notifies the host by setting the ISR_RCV bit in the memory based ISRand raises an interrupt. The SimbaHandleInterrupt routine in the drivercalls the SimbaRcvDpc routine to process the received frames.

[0465] The INIC driver maintains a queue of header SDBs, each of whichcontain 16 header buffers. The head of the HdrQueue is the current SDBbeing worked on, and the SDBHANDLE structure for that SDB contains theoffset of the next expected header buffer within the SDB (header buffersare returned to the driver in the order that they were presented to theINIC). Each valid header buffer found by the INIC driver is dequeued andprocessed. A buffer is dequeued by bumping the offset within theSDBHANDLE structure. Once all of the header buffers within an SDB areexhausted, we dequeue the SDB from the HdrQueue and start over again atthe top of the next SDB. A header buffer is determined to be valid bychecking the status field. The status field is cleared when the headerbuffers are passed to the INIC. The INIC sets valid bit of the statusfield when a buffer is returned to the INIC driver.

[0466] If an error exists in the frame, the INIC sets the IRHDDR_ERR bitin the status word, and forwards the receive frame status words to thehost. These status words are generated by the INIC hardware and placedin front of the receive frame. For more details regarding these statuswords, refer to the sections regarding the INIC hardware specification.

[0467] In the event of an error, the SimbaRcvDpc routine increments theappropriate statistics field in the ADAPT structure, and then drops thereceived frame.

[0468] If the INIC driver receives a normal network frame, it needs toensure that it is configured to receive the frame. We do this by callingthe SimbaMacFilter routine. If we are running in promiscuous mode, thenthis routine always returns true. If the destination MAC address equalsour MAC address and we are configured for directed mode, then we alsoreturn true. Or, if the destination MAC address is a broadcast addressand we are configured to receive broadcast packet, then we return trueas well.

[0469] Multicast frames are a bit trickier. When the INIC driverreceives a OID_(—)802_(—)3_MULTICAST OID in the SimbaSetInformationroutine, it downloads a 6-bit hash of the multicast address to the INICfirmware. This 6-bit hash is generated by computing the 8-bit CRCpolynomial generated by the MAC core and masking off the top two bits.When the firmware hands a multicast frame to us, we must ensure that weare configured to receive the multicast frame by checking for a perfectmatch against our list of multicast frames. If a match occurs, and weare configured to receive multicast frames, then the SimbaMacFilterroutine returns true.

[0470] There are three types of received frames that we must handle inthe SimbaRcvDpc routine: 1) fast path frames (or messages), 2) slow pathTCP frames, and 3) other frames.

[0471] Fast path frames are identified by the IRHDDR_TVALID bit in thestatus word. It means that the header buffer (and possibly data bufferas well), contains a frame or message associated with a fast pathconnection on the INIC. Under these circumstances we must send thereceived frame strictly to the ATCP driver.

[0472] If the IRHDDR_TVALID bit is not set, then the header buffer, orassociated data buffer, contains a normal network frame. If the networkframe is a TCP frame for one of the network interfaces in our system,then the INIC driver needs to send the frame up to the ATCP driver. Thisis a slow path TCP frame. Otherwise the INIC driver needs to send it upto the Microsoft TCP driver. Note that we only send the frame up to theATCP driver if it is a TCP frame that is destined for one of ourinterfaces. We must check the destination IP address because if is notdestined for one of our interfaces, then the frame needs to be routed.Frames that need to be routed are done so via the normal Microsoft TCPstack. Note also that we forward the frame up to the ATCP driver if theframe is destined for any interface in our system, not just the INICinterfaces. This is because if the frame came in on our interface, it islikely to go out on our interface. Under these circumstances, we musthandle it in the ATCP driver.

[0473] Frames that are sent from the INIC driver to the ATCP driver aredone so by calling SimbaIndicateHeader. Frames that are sent up to thenormal TCP driver are done so by calling SimbaIndicateData.

[0474] When we wish to send a frame up to the ATCP driver via aSimbaIndicateHeader, we do so by sending up the entire header buffer. Wedo this because the header buffer may contain information that isimportant to the ATCP driver. In order to send the header bufferexclusively to the ATCP driver we have to do two things.

[0475] First, in order to prevent the normal TCP driver (or any otherdriver) from attempting to parse the frame, we must make the frame looklike something that it doesn't want to touch. Remember that the driversabove an ethernet miniport driver expect an indicated frame to beginwith an ethernet header, and thus expect an ethernet type field to be ata twelve byte offset within the frame. We trick the other protocoldrivers by setting this “type” field to 0×666 (the same value used toidentify an ATCP command buffer in the transmit path).

[0476] The second thing that we must do is to get the frame past theNDIS filtering. NDIS performs ethernet frame filtering for us. If wesend up a frame that does not have the destination MAC address field setto our interface's MAC address, NDIS will drop it. There are two ways todeal with this. The first is to set the NDIS filtering to promiscuousmode. This way all frames are received by the protocol driver. This isundesirable because NDIS will then forward all outgoing frames back upto the ATCP driver. The other way is to set the first 6 bytes of theheader buffer (the destination MAC address) to our interfaces MACaddress. While this does require a 6-byte copy for every frame received,this was determined to be the best approach.

[0477] In order to indicate the header buffer, and possibly data buffer,upstream, we first map the buffers using NDIS buffer and packetdescriptors. Recall that for each header buffer we pre-allocate an NDISbuffer and packet descriptor, while for each data buffer we pre-allocatejust a buffer descriptor. We use these pre-allocated buffer and packetdescriptors here to map the buffer(s) and send them upstream. FIG. 18illustrates the relationship between all of these structures.

[0478] When indicating data we only want to send up the data portion ofthe frame alone. Recall that data can either reside in the header bufferitself, if it is small enough, or in an associated data buffer. If thedata resides in the header buffer, then we adjust the buffer descriptorsuch that it points to the data portion of the header buffer (beneaththe status word, etc). Conversely, if the data resides in the databuffer, we use the buffer descriptor associated with the data buffer topoint to the data buffer, and we use the packet descriptor associatedwith the header buffer to point to the data buffer descriptor. Aftersetting everything up we then free the header buffer, and the bufferdescriptor associated with it.

[0479] Once we have completed processing incoming data, we replace anycompleted header and data SDBs by issuing new SDBs to the INIC. Notethat we do this immediately, rather than waiting for the ATCP or otherprotocol driver to return the buffers to us.

[0480] In NDIS version 4, there are two ways in which a miniport drivercan indicate data to a protocol driver above it. The first method isperformed by calling NdisMEthIndicateReceive. With this method, the datapassed up is copied immediately into memory allocated by the protocoldriver. Thus, when the call is complete, the memory used to contain thedata can be freed. While this is simple from a resource managementperspective, it is horribly inefficient. The second method is performedby calling NdisMIndicateReceivePacket. With this method, the packetpassed up is held by the protocol driver until it has completedprocessing the entire data. With this method, we need a way of returningthe completed packets back to the miniport driver so the miniport drivercan free the memory. This is done via a call to NdisReturnPackets, whichresults in a call to the MiniportReturnPacket handler.

[0481] SimbaReturnPacket is the MiniportReturnPacket handler for theINIC driver. Note that the packet being returned to us contains a headerand/or a data buffer. As we described above, in order to free a headerbuffer or data buffer, we must have a pointer to the SDBHANDLEstructure, and we must also know the buffer offset within the SDB. Bothof these values are saved in the ProtocolReserved field of the packetdescriptor. The ProtocolReserved field is a section of memory within thepacket descriptor that is reserved for use by the miniport driver.

[0482] To send and receive frames (and commands) from the INIC we usethe mechanism described above regarding the host interface strategy forthe Alacritech INIC. Beyond this, however, we also need a mechanism toreceive other miscellaneous types of information from the INIC. Thisinformation includes statistics, link status (discussed above), and INICconfiguration information. To perform this function, we use a set ofcommands called Utility Processor Requests (UPRs).

[0483] UPRs are handled exclusively by the utility processor on theINIC. Each UPR command is initiated by writing to the correspondingregister on the INIC. The address written to the register tells the INICwhere to place the data. For example, if we wish to fetch the INICconfiguration from the INIC, we write the address of the INICconfiguration shared memory space to the RCONFIG register of the INIC.

[0484] UPRs complete asynchronously by setting a bit in the ISR, andsetting an interrupt. Because there is no identification as to which UPRhas completed, we only keep one UPR outstanding per interface at anygiven time. If a UPR is already in progress, then a subsequent UPR willbe queued behind it. When the pending UPR completes, the queued UPR willbe issued.

[0485] NT requires that an NDIS driver provide the following statistics:successful transmits, successful receives, transmit errors, receiveerrors, dropped receives (no buffer), and transmit collisions.

[0486] The majority of these statistics are maintained on the INIC. Whenthe INIC driver receives a QueryInformation call for one of thesestatistics, we issue a stats UPR command to the INIC and return pending.When the UPR completes we in turn complete the pending QueryInformationcall with the requested information.

[0487] The Microsoft stack maintains a number of statistics about eachinterface such as multicast receives, broadcast receives, unicastreceives, multicast transmits, etc. It also maintains TCP levelstatistics such as the number of segments sent and received, and thenumber of TCP bytes sent and received. Since the INIC offloads the TCPstack from the NT system, we can not maintain these statistics in theATCP driver. Instead, we maintain most of these statistics on the INICitself. When the ATCP driver requires these statistics, it issues anOID_SIMBA_GET_STATS OID to the INIC driver. The INIC driver againfetches these statistics by issuing a UPR to the INIC and returns thestatistics back to the ATCP driver.

[0488] The INIC keeps track of received TCP segments and bytes by simplylooking at the protocol field of the IP header. It does not, however,examine the destination IP address. It is possible that one of thereceived TCP frames may need to be forwarded back out another interface.In this case, the frame never reaches the TCP layer, and thus, it shouldnot be reflected in the TCP statistics. We adjust for this in the INICdriver when we discover that a frame is not associated with any of theinterfaces in our system.

[0489] There are a number of other statistics that we maintain in theADAPT structure explicitly for the purpose of debugging. These includecounters of just about any error condition, or error frame encounteredin the INIC driver. It also includes various other counters, such asinterrupt and event counters, that we may use later to tune and optimizethe driver.

[0490] Two families of diagnostics are specified, hardware diagnostics,and firmware diagnostics. The hardware diagnostics are split intoseveral applications, engineering hardware diagnostics, manufacturingdiagnostics, and customer diagnostics.

[0491] Each of the firmware and hardware diagnostic applicationsrequires a way to communicate directly with the INIC. To do this weprovide a set of standard device driver entry points in our INIC NDISdriver. We accomplish this by saving the NDIS entry points that arefound in our DriverObject structure, and replacing them with our ownopen, close, write, read, and ioct1 routines. When one of these routinesis called, we check the device extension of the device object that isassociated with the call. If the extension is not associated with ourdiagnostic device, then we pass the call off to the saved correspondingNDIS routine. Otherwise we intercept and handle the call directly.

[0492] The firmware diagnostics provide a mechanism to exercise andverify some level of INIC microcode functionality. By putting the INICinto loopback mode, we can send and receive slow-path frames. To ensurethat we are exercising as much of the final product as possible withthese diagnostics, we also use the majority of the INIC driver transmitand receive code.

[0493] To send data passed down from the diagnostic application, weallocate a chunk of memory used to contain the users data, and anotherchunk of memory, which we will use as a command buffer. We copy in theuser's frame our allocated memory and initialize the command buffer. Wethen map the command buffer and a statically allocated ethernet headerwith NDIS buffer and packet descriptors and call the SimbaTransmitPacketroutine to send the data.

[0494] Note that in allocating our own command buffer and pre-pending itwith a separate ethernet header (containing a type of 0×666), we arepretending to the SimbaTransmitPacket routine to be the ATCP driversending down a command buffer (see the ATCP Command Buffer descriptionabove).

[0495] The SFWDiagSend routine will return success to the userimmediately, rather than waiting for the INIC to respond to the commandbuffer. This allows the diagnostic application to get many transmitcommands operating in parallel.

[0496] When we receive a command completion event from the INIC, theSimbaHandleInterrupt routine calls the SimbaXmtDpc routine. If theSimbaXmtDpc routine finds that diagnostics are currently running, itwill pass the completion off to the SFWDiagSendComplete routine. TheSFWDiagSendComplete will simply free the resources allocated bySFWDiagSend.

[0497] When we are running in diagnostic mode, the SimbaRcvDpc routinecalls the SFWDiagIndicateData routine instead ofNdisIndicateReceivePacket when a packet has arrived. TheSFWDiagIndicateData routine places the received packet on a queue andissues an event to wake up any thread that might be waiting inSFWDiagRecv.

[0498] The SFWDiagRecv routine is called by the diagnostic applicationto receive an expected frame. It waits for a received frame to beindicated by the SFWDiagIndicateData routine and then dequeues the framefrom the diagnostic receive queue. The data contained in the packet iscopied out to the user, and the packet is then returned by callingSimbaReturnPacket.

[0499] Hardware diagnostics are used to verify the functionality of theINIC hardware. To do so requires that we run special diagnosticmicrocode on the INIC. When hardware diagnostics are initiated, the INICdriver resets the INIC card and downloads the diagnostic microcode.After the user exits hardware diagnostics, the INIC is put back intooperational mode by downloading the standard microcode andre-initializing the card and interfaces.

[0500] Nearly every function entry and exit in the INIC driver can betraced using the SIMBA_TRACE tracing facility. Furthermore, everynotable event, such as an error, is traced as an important or criticaltrace event. The SIMBA_TRACE facility keeps a circular log of traceevents in system memory. It can be disabled with a compile time optionso that in the production driver there is no performance impact.

[0501] The SIMBA_TRACE facility is set up so that a common buffer isused to track events from both the ATCP and INIC driver. This isachieved by passing the common buffer address using theOID_SMBA_ATK_GLOBALS set OID.

[0502] For installation, the INIC driver searches for newly installedcards by calling the GetPCIInformation utility with the vendor anddevice ID of the INIC device. For each four-port INIC, GetPCIInformationshould return four separate devices, each with a unique function number(0-3). For each device returned by GetPCIInformation we must check tosee if it is already installed before proceeding with the installation.Typically this would be as simple as calling theIsNetCardAlreadyInstalled utility, but Microsoft apparently thought thatno one would ever write a multifunction networking card, so they didn'tput multifunction support in the utility. We have then combined thefunctionality of the IsNetCardAlreadyInstalled utility and support formultifunction devices to our own version of the utility.

[0503] Having determined that we have not already installed the device,we set the CardBase to the slot number of the card, with the high orderbits set to the bus number. This is somewhat more confusing then settingit to the base network number, as is done in the VPCI phase, but it ismore permanent in the event that an administrator starts installing andde-installing adapters. We also save the bus number, slot number andfunction number separately, along with the size of the card and theindex of the adapter within the card.

[0504] The bulk of the source code for the INIC driver is located in thedriver/simba directory in the source tree. Other miscellaneous headerfiles are scattered about in other directories as specified below.

[0505] The following files are found in the Simba source directory:

[0506] simba.c—Contains the DriverEntry routine for the INIC driver,

[0507] simba.h—The main header file for the INIC driver, this containsthe SIMBA_DRIVER, SIMBA_CARD and ADAPT structures, as well as many otherstructures and definitions,

[0508] simbamini.c—The miniport entry points and related functions,

[0509] simbamisc.c—Miscellaneous support routines for the INIC driver.Contains most of the initialization and buffer management code,

[0510] endian.h—Endian swapping definitions used when parsing networkframe headers,

[0511] simbadownload.c—The microcode download for the INIC. This is atwo-dimensional statically defined character array generated by theobjtoc utility,

[0512] simbaproto.c—The protocol driver routines for an initial (VINIC)phase of the driver, this is not included in an intermediate (VPCI) orFINAL phase of the driver,

[0513] vpci.c—The entry points for VPCI requests,

[0514] vpci_driver.h—Definitions used to create and parse VPCI networkrequests

[0515] ne2000.c—The DriverEntry and miniport routines for the ne2000portion of the INIC VPCI driver,

[0516] ne2000sw.h—The main software definitions for the ne2000 portionof the INIC VPCI driver,

[0517] ne2000hw.h—The hardware definitions for the ne2000 NICcard.c—Low-level ne2000 network card routines,

[0518] interrupt.c—Interrupt, transmit and receive routines for thene2000 portion of the INIC VPCI driver,

[0519] diag.c—Hardware and firmware diagnostic routines,

[0520] diag.h—Definitions used by the diagnostic routines,

[0521] diagdownload.c—The diagnostic microcode download for the INIC.Also a two dimensional array generated by the objtoc utility,

[0522] oemsetup.*—installation scripts for the VINIC, VPCI, and FINALphase of the INIC driver,

[0523] precomp.h—Precompilation header file containing all of theincluded header files,

[0524] sources.*—compilation directives for the VINIC, VPCI and FINALphase of the driver,

[0525] update.bat—A quick and dirty batch file used to update drivers ona test machine,

[0526] buildit.bat—A quick and dirty batch file used to build andinstall the INIC driver,

[0527] config.bat—A quick and dirty batch file used to configure theINIC driver for the VINIC, VPCI, or FINAL phase.

[0528] Other relevant files include:

[0529] driver/include/simbahw.h—Contains definitions about the INIChardware and firmware,

[0530] driver/include/pci h—Contains general PCI configuration spacedefinitions,

[0531] driver/include/simbamisc.h—Contains miscellaneous softwaredefinitions shared between the INIC and ATCP driver,

[0532] tools/diag/include/diagctl.h—Contains definitions shared betweendiagnostic applications and the diagnostic portion of the INIC driver,

[0533] tools/include/vpci.h—Contains definitions about VPCI commands.Shared by other VPCI users such as the AGDB utility.

[0534] The next several pages describe the design of the microcode thatexecutes on the microprocessors of the INIC. The overall philosophy ofthe INIC is discussed above, while the detailed configuration isdescribed below, leaving this section to discuss the INIC microcode indetail.

[0535] The following acronyms are defined for the INIC microcode:

[0536] ACK=Transport layer acknowledgement;

[0537] BC=Broadcast frame;

[0538] CCB=Communications Control Block; a block of control informationpassed between the host and the INIC to control a connection;

[0539] FSM=Finite state machine; a state/event matrix giving action andnext state;

[0540] ISR=Interrupt Status Register;

[0541] LRU=Least Recently Used; used in the SRAM CCB buffer cache;

[0542] MC=Multicast frame;

[0543] MSS=Maximum segment size;

[0544] PST=Persist timer;

[0545] RTR=Retransmission timer.

[0546] As specified in below, the INIC has a set of 3 custom processors(CPUs) that provide considerable hardware-assist to the microcoderunning thereon. The following paragraphs list the main hardware-assistfeatures.

[0547] The INIC has 32 hardware queues whose sizes are user-definable;they can be used in any manner by the CPUs (and the hardware) forpassing 32-bit pointers/events around without interlock issues whenadding or removing entries from the queues (e.g., DRAM free-bufferqueues, receive-frame queues etc.).

[0548] The INIC also has a Receive hardware sequencer that completelyvalidates an input header as the frame is being received by the MAC,validates TCP and IP checksums, generates a frame status and a contextlookup hash, moves the frame into a DRAM buffer and queues the frameaddress and status for processing by the Receive CPU into one of thehardware queues mentioned above.

[0549] A set of Transmit sequencers work from the above-mentioned queuesto transmit frames. Like the Receive sequencers, there is one Transmitsequencer per interface.

[0550] The INIC also has a custom 32-bit protocol processor that iseffectively 3 CPUs using shared hardware in a 3-level pipelinedarchitecture. The protocol processor provides separate instruction anddata paths to eliminate memory contention.

[0551] Multiple register contexts or process slots are provided withregister access controlled by simply setting a process register. Theprotocol processor provides 512 SRAM-based registers to be shared amongthe 3 CPUs in any way desired. The current implementation uses 16processes of 16 registers each, leaving 256 scratch registers to beshared. This includes a set of CPU-specific registers that are the samelocal-cpu register number, but for which the real register is determinedby an offset based on the CPU number; this allows multiple CPUs toexecute the same code at the same time without register clashes orinterlocks. These registers are a part of the above-mentioned scratchpool.

[0552] A specialized instruction set is provided to the CPUs to assistnetwork processing: endian-swap instructions, a hash instruction togenerate hash indexes, embedded interlocks and instructions to set them,and a hardware-implemented LRU mechanism.

[0553] Seven separate DMA engines are built into the INIC hardware. Theone to be used at any time is defined by the source and destinatione.g., from SRAM to PCI, from DRAM to SRAM; the DMA works off 32descriptors in SRAM, and at present, the code allocates one descriptorpermanently to each process. Completed DMAs are determined by simplyinspecting the Channel Events register.

[0554] The following design choices were made in the currentimplementation. RECEIVE processing is run on one CPU, TRANSMITprocessing on another and the third CPU is used as a UTILITY and DEBUGprocessor. Splitting receive and transmit was chosen as opposed toletting 2 CPUs both run receive and transmit. Initially one of the mainreasons for this was that the planned header-processing hardware couldnot be shared and interlocks would be needed to do this. However, thereceive hardware CPU now runs completely independently, and passesframes to the Receive CPU via a hardware queue described above,rendering the above issue moot. A good reason now for separating theprocessor functions is that parts of the code depend on the exclusiveuse of some shared resources by a particular CPU and interlocks would beneeded on them. It is expected that the cost of all these interlockswould be fairly high, but perhaps not prohibitive. Another reason isthat the CPU scratch registers have been carefully divided between the 3CPUs. If multiple CPUs executed receive processing for example, thenthey would be using each other's scratch registers.

[0555] The INIC supports up to 256 TCP communication control blocks(CCBs). A CCB is associated with an input frame when the frame's sourceand destination IP addresses and source and destination ports match thatof the CCB. For speed of access, there is a CCB index in hash order inSRAM. The index can be searched based on the hardware-generated hash tofind a CCB entry that matches the frame. Once a match has been found,the CCB is cached in SRAM. There are up to 16 cached CCBs in SRAM. Thesecache locations are shared between both CPUs so that the CPU with theheavier load will be able to use more cache buffers. There are 8 headerbuffers for receive and 8 command buffers for transmit to be sharedamong the processes on the CPUs. Note that each header/command buffer isnot statically linked to a specific CCB buffer. Instead the link isdynamic on a per-frame or per-command basis. The use for this dynamiclinking will be explained in later sections.

[0556] Two basic processor implementations were considered: asingle-stack and a process model. The process model was chosen herebecause the custom processor design is providing near zero-cost overheadfor process switching through the use of a process base register, andbecause there will be more than enough process slots available for thepeak load. It is also expected that all “local” variables will be heldpermanently in registers whilst an event is being processed. Thefeatures that provide this are:

[0557] 256 of the 512 SRAM-based registers are used for the registerprocess slots. This is divided into 16 process slots of 16 registerseach. Then 8 of these are reserved for receive and 8 for transmit. ALittle's Law analysis has shown that in order to support 512 byte framesat maximum arrival rate of 4*100 Mbits, requires more than 8 jobs to bein process in the NIC. Each job requires an SRAM buffer for a CCBcontext and at present, there are only 16 of these, 8 per CPU, due toSRAM limitations. So more process slots (eg 32*8 regs each) do not seemworthwhile.

[0558] A process context switch simply involves reloading the processbase register based on the process to be restarted, and jumping to theappropriate address for resumption. To better support the process modelchosen, the code locks an active CCB into an SRAM buffer while eitherCPU is operating on it. This implies there is no swapping to and fromDRAM of a CCB once it is in SRAM and an operation is started on it. Morespecifically, the CCB will not be swapped after requesting that a DMA beperformed for it. Instead, the system switches to another activeprocess. Once the DMA is complete, it will resume the former process atthe point directly after where the DMA was requested. This constitutes azero-cost switch as mentioned above.

[0559] Receive and transmit processing on an individual CCB are eachcontrolled by separate state machines; the state machines are run fromwithin a process.

[0560] The initial INIC has 16 MB of DRAM. Utility initializationmicrocode divides a large portion of this into 2K buffers that will bequeued to the Q_FREEL hardware queue. These queues are also used tocontrol small host buffers, large host buffers, command buffers andcommand response buffers, events from one CPU to the other, etc.

[0561] Each CPU handles its own timers independently of the others;there are 2 timer bits in the General Events register which are both setto 1 every 2 milliseconds and can be cleared independently; so Receiveand Transmit CPU's effectively each have their own timer bit. Asdescribed above, contexts (CCBs) are passed to the INIC through theTransmit command and response buffers. INIC-initiated CCB releases arehandled through the Receive small buffers. Host-initiated releases usethe Command buffers. There is strict handling of the acquisition andrelease of CCBs to avoid windows where for example, a frame is receivedon a context just after the context was passed to the INIC, but beforethe INIC has “accepted” it, as described in detail above.

[0562] The initial implementation of the INIC may not handle T/TCPconnections, since they are typically used for the HTTP protocol and theclient for that protocol typically connects, sends a request anddisconnects in one segment. The server sends the connect confirm, replyand disconnect in his first segment. Then the client confirms thedisconnect. This is a total of 3 segments for the life of a context.Typical data lengths are on the order of 300 bytes from the client and3K from the server. The INIC will provide as good an assist as seemsnecessary here by checksumming and validating the frame. The latter isonly likely when data is forwarded with a request such as when afilled-in form is sent by the client. Note however that the INIC willsupport HTTP over a normal TCP connection in fast-path mode. Also notethat later implementations handle T/TCP, SPX and UDP.

[0563] Table 2 summarizes SRAM requirements for the Receive, Transmitand Utility CPUs: TABLE 2 Hardware use (DRAM FIFOs etc) 5120 CCB buffers256 bytes * 16 4096 CCB headers  16 bytes * 256 4096 Header buffers 128bytes * 8 1024 Command buffers 128 bytes * 8 1024 Debugger/Stats etc1024 16K bytes

[0564] As described above, the host determines when a TCP connection isable to be handed to the INIC, setup the CCB and pass it to the card viaa command in the Transmit queue. CCBs that the INIC owns can be handedback to the host via a request from the Receive or Transmit CPUs or fromthe host itself at any time.

[0565] When the INIC receives a frame, one of its immediate tasks is todetermine if the frame is for a CCB that it controls. If not, the frameis passed to the host on what is termed the slow-path. On transmit, thetransmit request will specify a CCB number if the request is on anINIC-controlled CCB. Thus the initial state for the INIC will betransparent mode in which all received frames are directly passedthrough and all transmit requests will be simply thrown on theappropriate wire. This state is maintained until the host passes CCBs tothe INIC to control. Note that frames received for which the INIC has noCCB (or it is with the host) will still have the TCP and IP checksumsverified if TCP/IP. Similarly the host can request that the INICcalculate and insert the checksums on a transmit request for which theINIC has no CCB. There are 512 registers available in the INIC. Thefirst 256 are used for process slots. The remaining 256 are splitbetween the 3 CPUs. Table 3 lists the register usage. TABLE 3 RegisterUsage  0-255: 16 processes, 16 registers each; 256-287: 32 for RCVgeneral processing; 288-319: 32 for XMT general processing; 320-367: 48for UTL (CPU 3); 368-383: 16 for RCV/XMT processing; 384-415: 32CPU-specific for RCV; 416-447: 32 CPU-specific for XMT; 448-479: 32CPU-specific for UTL; 448-511: 64 for UTL scratch.

[0566] The following sources of events exist in the INIC:

[0567] 1) A Receive input queue—Hardware will automatically DMA arrivingframes into frame buffers and queue an event into the Q_RECV hardwarequeue.

[0568] 2) A General Event register for Timer events—Expiration of the 2millisecond timer will set 2 bits in this register, one for eachprocessor.

[0569] 3) Transmit request queues—There is one queue allocated perinterface for requests from the host processor. These requests come viathe Utility CPU, which initially DMAs the request into a small DRAMbuffer and then queues a pointer to that buffer to the appropriateTransmit request queue.

[0570] 4) Receive and Transmit CCB events queues—these queues are usedto pass events to be processed against a CCB state machine. The eventsmay initiate in any of the CPUs.

[0571] 5) Receive and Transmit System queues: these queues are used forsystem events i.e. those not directed at a specific CCB.

[0572] 6) The Channel Events register: this register contains theDMA-completed bits for all 32 DMA descriptors; there will be onedescriptor allocated for each of the 16 processes, so that when therelevant bit is set in the Channel Events register, the DMA that thatprocess fired off is complete.

[0573] As mentioned earlier, there are 16 process slots in which toexecute. The first 8 are allocated to the Receive CPU, the next 8 to theTransmit CPU.

[0574] The microcode is split into 6 sections based on functionality.These sections are:

[0575] The Mainloop;

[0576] Receive frame processing;

[0577] Receive event processing for CCB events;

[0578] Receive command processing;

[0579] Transmit command processing;

[0580] Transmit event processing for CCB events.

[0581] Within each of these divisions exist subdivisions. For example,receive-frame processing has code for non-CCB frames (“slow-path”), andfor CCB frames (“fast-path”). These sections will be discussed in thefollowing few pages.

[0582] Receive and Transmit share the same Main Loop code. This is madepossible because of the CPU-specific registers defined by the hardwaree.g., 384-415, 416-447. Also the functions that the mainloops need toperform are identical. The major functions are:

[0583] to check if any DMAs have completed,

[0584] to determine if any process are now restartable,

[0585] to see if a timer tick has occurred,

[0586] scan all the hardware queues for new events for this CPU.

[0587] The following is a C-like summary of the main loop: forever { while(dma_events & OUR_CPU_MASK) {   clear dma_event bit;   restartwaiting process process;  }  while any processes are runable {   runthem by jumping to the start/resume address;  }  if (timer_tick) {  reset timer_tick bit;   jump to this_cpu_timer_rtne;  }  if (availableprocess entries) {   while(q_out_rdy & OUR_QUEUES_MASK) {    callappropriate event handler to service the event;    this will setup a newprocess to be run (get free process entry,    header buffer, CCB buffer,set the process up).   }  } }

[0588] Receive-frame processing can be broken down into the followingstages:

[0589] First, Receive Dequeue and Header Validation, which includesconsiderable hardware assist. Much header validation is implemented inhardware in conjunction with MAC processing by scanning the data as itflies by. The Receive hardware sequencer performs a number of tests togenerate status from the various headers.

[0590] For the MAC header the Receive hardware sequencer determines ifEthernet/802.3, if MC/BC, if it matches our MAC address A or B,determines the network protocol, and flags if not a MAC status of “goodpacket.”

[0591] For the Network header the Receive hardware sequencer determinesif header checksum is valid, header length is valid (e.g. IP>=5),network length>header length, what the transport protocol is, if thereis any fragmentation or network options, and whether the destinationnetwork address is ours.

[0592] For the Transport header the Receive hardware sequencerdetermines if the checksum is valid (incl. pseudo-header if relevant),header length is valid (e.g. TCP>=5), length is valid, what is thesession layer protocol (e.g. SMB, HTTP or FTP data), are there anytransport flags set (e.g. FIN/SYN/URG/RST bits), and any optionspresent.

[0593] As frames are received by the INIC from a network, they areplaced into 2K-byte DRAM buffers by the Receive hardware sequencer,along with 16 bytes of the above frame status. A pointer to the lastbyte +1 of this buffer is queued into the Q_RECV queue. The pointercontains a bit (bit 29) that informs the microcode if this frame isdefinitely not a fast-path candidate (e.g., not TCPIP, or has an errorof some sort). Receive frame processing involves extracting this pointerfrom the Receive hardware queue, and setting up a DMA into an SRAMheader buffer of the first X bytes from the DRAM frame buffer. The sizeof the DMA is determined by whether bit 29 is set or not. If it is set(this frame is not a fast-path candidate), then only the status bytesare needed by the microcode, so the size would be 16 bytes. Otherwise upto 92 bytes are DMA'd—sufficient to get all useful headers. When thisDMA is complete, the status bytes are used by the microcode to determinewhether to jump to fast-path or slow-path processing.

[0594] If bit 29 is set, this frame is going slow-path. Effectively thismeans that the frame will not be processed against an on-INIC CCB. Itwill be passed directly to the host, although if the frame is TCP/IP,then its checksums have already been validated by the hardware. Also,all other header validations have been performed.

[0595] If bit 29 is not set, then there may be an onboard CCB for thisframe. The Receive sequencer has already generated a hash based on thenetwork and transport addresses, e.g., IP source and destinationaddresses and TCP ports. This hash is used to index directly into a hashtable on the INIC that points to entries in a CCB header table. Theheader table entries are chained on the hash table entry. The microcodeuses the hash to determine if a CCB exists on the INIC for this frame.It does this by following this chain from the hash table entry, and foreach chained header table entry, comparing its source and destinationaddresses and ports with those of the frame. If a match is found, thenthe frame will be processed against the CCB by the INIC. If not, thenthe frame is sent for slow-path processing.

[0596] In the first product, the fast-path has been implemented as afinite state machine (FSM) that covers 3 layers of the protocol stack,i.e., IP, TCP and Session. The state transitions for the Receive FSM andthe events that cause them are discussed below.

[0597] The following summarizes the steps involved in normal fast-pathframe processing:

[0598] 1) Get control of the associated CCB; this involves locking theCCB to stop other processing (e.g. Transmit) from altering it while thisreceive processing is taking place.

[0599] 2) Get the CCB into an SRAM CCB buffer; there are 16 of thesebuffers in SRAM and they are not flushed to DRAM until the buffer spaceis needed by other CCBs. Acquisition and flushing of these CCB buffersis controlled by a hardware LRU mechanism. Thus getting the CCB into abuffer may involve flushing another CCB from its SRAM buffer.

[0600] 3) Examine the frame header to generate an event from it. TheReceive events that can be generated on a given context from a frameare:

[0601] receive a valid and complete Session layer packet;

[0602] receive a valid and incomplete Session layer packet;

[0603] receive a pure ACK;

[0604] receive an “invalid” frame, i.e., one that causes the CCB to beflushed to the host;

[0605] receive a window probe;

[0606] receive a partial/split NetBios header.

[0607] 4) Process the event against the CCBs FSM using that frame.

[0608] Each event and state intersection provides an action to beexecuted and a new state. The following is an example of a state/eventtransition, the action to be executed and the new state: Assume thestate is IDLE (SR_NI), and the event is VALID INCOMPLETE RECEIVE FROMTHE RCV QUEUE (ER_VRIR). The action from this state/event intersectionis AR_RPHH and the next state is WAIT MDL, CCB Q EXISTS (SR_WMTQ). Tosummarize, the first of an incomplete Session layer packet has beenreceived. For example, if the Session layer is NetBIOS, then this framecontains the NetBIOS header, but it does not contain all the Sessionlayer data. The action performs the following steps:

[0609] 1) DMA a small amount of the payload (192 bytes) into a smallhost header buffer;

[0610] 2) Process the amount sent to the host through TCP—it has beendelivered;

[0611] 3) Queue the frame to the internal CCB frame queue in the CCBSRAM buffer;

[0612] 4) DMA appropriate receive status into the header buffer,including setting the COMPLETE bit;

[0613] 5) Post ISR status to the Utility CPU via the Q_EVENT2 queue, sothat it will generate a host interrupt with it;

[0614] 6) Generate an event to the Transmit CPU via the Q_EVENT1 queueto check if output is now possible; and

[0615] 7) Exit from Receive FSM processing.

[0616] The following steps summarize slow-path Receive processing by theINIC:

[0617] 1) Examine frame status bytes to determine if frame is in-error;if so, only these status bytes will be sent to the host;

[0618] 2) Move the frame into either a small or a large host buffer viaDMA. It is not split across these buffers;

[0619] 3) Set frame status and address details and DMA status to thehost;

[0620] 4) Send event to the Utility processor to post Receive status inthe ISR.

[0621] Once the INIC is handling CCBs, i.e. fast-path processing, thereare numerous other events that need to be processed apart from receivedframes for that CCB. The following are the relevant events:

[0622] lock a new context (from Xmit);

[0623] unlock a new context (from Xmit);

[0624] receive frame (complete or incomplete) from the CCB queue;

[0625] receive window update from the CCB queue;

[0626] receive a partial/split NetB header from the CCB queue;

[0627] end of the CCB queue of frames;

[0628] flush context request from host;

[0629] flush context request from Xmit;

[0630] context release/flush complete from Xmit.

[0631] The following summarizes Receive Event processing:

[0632] 1) Get control of the associated CCB; this involves locking theCCB to stop other processing (e.g. Transmit) from altering it while thisprocessing is taking place;

[0633] 2) Get the CCB into an SRAM CCB buffer;

[0634] 3) If the event is “Check CCB queue”, check the internal queue inthe CCB; if there are frames queued, dequeue the next one, get itsheader into an SRAM header buffer and examine it to generate a specificevent; if no frames are queued, exit;

[0635] 4) Either way, process the event against the CCB's FSM.

[0636]FIG. 19 provides a state diagram summary of the Receive FSM statesand the main events and transitions. Processing Receive Commands by theINIC occurs when the host posts a receive MDL to the INIC by filling ina command buffer with appropriate data pointers, etc., and posting it tothe INIC via the Receive Command Buffer Address register. Note thatthere is only one host receive MDL register. The INIC Utility CPU willDMA the command in and place a pointer to it in the Q_RCMD queue whichthe Receive CPU will work on.

[0637] There are two possible commands sent to the INIC from the hostand both apply only to fast-path processing. The commands are:

[0638] Receive MDL for remaining session-layer data;

[0639] Abort/flush a context.

[0640] The following summarizes Receive Command processing:

[0641] 1) Get an SRAM command buffer and get the first 32 bytes of thecommand into it;

[0642] 2) Determine the CCB involved and get control of it; thisinvolves locking the CCB to stop other processing (e.g. Transmit) fromaltering it while this processing is taking place;

[0643] 3) Get the CCB into an SRAM CCB buffer;

[0644] 4) Generate an event based on the command type;

[0645] 5) Process the event against the CCB's FSM.

[0646] As mentioned above, the fast-path has been implemented as afinite state machine (FSM) that covers at least 3 layers of the protocolstack, i.e., IP, TCP and Session. There are actually separate FSMs forReceive and Transmit. The state involved is the state of the CCBconnection (Receive or Transmit) and encompasses those 3 layers. Eventsare generated from the sources of events detailed earlier, and they areapplied against the FSM giving an action to execute and a new state.

[0647] Several Receive details should be noted. First, regarding windowupdates from the host, the host application has to tell the INIC whenthat application has accepted the received data that has been queued.This is so that the INIC can update the TCP receive window. This isachieved by piggybacking these on transmit or receive MDLs on the sameCCB. Second, for an INIC-controlled CCB, the INIC does not maintain akeepalive timer. This leaves the host with the job of determining thatthe CCB is still active. Third, a Timestamp option is supported in thefast path because it leads to better round-trip estimations (RTT) forTCP. However this is optional depending upon SRAM size limitations onthe on-INIC CCB. Fourth, the INIC maintains an Idle timer for CCBs underits control.

[0648] Transmit Command Processing begins when the host posts a transmitrequest to the INIC by filling in a command buffer with appropriate datapointers, etc., and posting it to the INIC via the Command BufferAddress registers. Note that there is one of these registers perinterface. The INIC Utility CPU will DMA the command in and place it inthe appropriate Q_XMIT queue which the Transmit CPU will work on. Thereis also one of these queues per interface so that transmit processingcan round-robin service these queues to keep all interfaces busy, andnot let a highly-active interface lock out the others (which wouldhappen with a single queue).

[0649] There are 4 possible commands sent to the INIC from the host. Thecommands are:

[0650] 1) Null command essentially just a window update; fast-path only;

[0651] 2) New context pending; fast-path only;

[0652] 3) New context confirm; fast-path only;

[0653] 4) Transmit command; fast- and slow-path.

[0654] The following summarizes Transmit Command processing:

[0655] 1) Get an SRAM command buffer and get the first 32 bytes of thecommand into it;

[0656] 2) Determine if there is a CCB involved and if so, get control ofthe it; this involves locking the CCB to stop other processing (e.g.Transmit) from altering it while this processing is taking place;

[0657] 3) If a CCB is involved, get the CCB into an SRAM CCB buffer, andgenerate an event based on the command type; then process that eventagainst the CCB's FSM;

[0658] 4) Otherwise perform slow-path transmit command processing.

[0659] For Transmit Slow-Path Processing, the queued request willalready have been provided by the host stack with the appropriate MACand TCP/IP (or whatever) headers in the frame to be output. Also therequest is guaranteed not to be greater than MSS-sized in length. So theprocessing is fairly simple. A large buffer is acquired and the frame ismoved by DMA into it, at which time the checksum is also calculated. Ifthe frame is TCP/IP, the checksum will be appropriately adjusted ifnecessary (pseudo-header etc) and placed in the TCP header. The frame isthen queued to the appropriate MAC transmit interface. Then the commandis immediately responded to with appropriate status through the HostResponse queue.

[0660] The following summarizes the steps performed:

[0661] 1) Get the remainder of the command if larger than 32 bytes, intothe SRAM command buffer. This implies that a slow-path command cannot belarger than the size of the SRAM command buffer (128 bytes);

[0662] 2) Examine command to determine if output TCP/IP checksumming isrequired;

[0663] 3) When output checksumming is required:

[0664] The host sets the length of the MAC through TCP headers into thecommand for the INIC. This is so that the Receive CPU may DMA the headerinto an SRAM buffer to calculate and set the IP/TCP checksums. Use halfof the command buffer as a header buffer for this purpose. This avoidsusing an SRAM CCB buffer that would cause an unnecessary flush to DRAMof a CCB buffer. Doing this may result in unused command fields beingmoved down over those fields that have already been loaded into CPUregisters, so as to gain space in the SRAM buffer. Even with this trick,there is a maximum header size that the host can send for a frame forwhich checksumming is requested (82 bytes).

[0665] DMA the header from host memory to the header buffer, then DMAthe remainder of the frame from the host to the appropriate offset in alarge DRAM buffer, leaving room for the frame headers. Note that thecommand is derived from an MDL on the host and may containscatter/gather lists that need to be processed. This latter DMA willprovide the TCP checksum of the payload. Manually calculate and insertthe IP checksum in the SRAM header buffer. Then calculate the checksumof the TCP header and pseudo-header in the SRAM header buffer and add inthe payload checksum. Insert the TCP checksum into the frame header.Then DMA the entire header to the front of the DRAM buffer and queue thebuffer to the appropriate Xmit hardware queue based on the requestedinterface in the command. Post new ISR status to the Utility processorto be passed to the host.

[0666] 4) When no checksumming is required:

[0667] DMA the entire frame from host memory into a large DRAM bufferand queue the buffer to the appropriate Xmit hardware queue based on therequested interface in the command. Note that the command is derivedfrom an MDL on the host and may contain scatter/gather lists that needto be processed. Post new ISR status to the Utility processor to bepassed to the host.

[0668] The following is an overview of the Transmit fast-path flow oncea command has been posted. The transmit request may be a segment that isless than the MSS, or it may be as much as a full 64K Session layerpacket. The former request will go out as one segment, the latter as anumber of MSS-sized segments. The transmitting CCB must hold on to therequest until all data in it has been transmitted and acked. Appropriatepointers to do this are kept in the CCB. To create an output TCP/IPsegment, a large DRAM buffer is acquired from the Q_FREEL queue. Thendata is DMAd from host memory into the DRAM buffer to create anMSS-sized segment. This DMA also checksums the data. The TCP/IP headeris created in SRAM and DMAd to the front of the payload data. It isquicker and simpler to keep a basic frame header permanently in the CCBand DMA this directly from the SRAM CCB buffer into the DRAM buffer eachtime. Thus the payload checksum is adjusted for the pseudo-header andplaced into the TCP header prior to DMAing the header from SRAM. Thenthe DRAM buffer is queued to the appropriate Q_UXMT transmit queue. Thefinal step is to update various window fields etc in the CCB. Eventuallyeither the entire request will have been sent and acked, or aretransmission timer will expire in which case the context is flushed tothe host. In either case, the INIC will place a command response in theResponse queue containing the command buffer handle from the originaltransmit command and appropriate status.

[0669] The above discussion has dealt with how an actual transmitoccurs. However the real challenge in the transmit processor is todetermine whether it is appropriate to transmit at the time a transmitrequest arrives, and then to continue to transmit for as long as thetransport protocol permits. There are many reasons not to transmit: thereceiver's window size is <=0, the Persist timer has expired, the amountto send is less than a full segment and an ACK is expected/outstanding,the receiver's window is not half-open etc. Much of transmit processingwill be in determining these conditions.

[0670] The fast-path has been implemented as a finite state machine(FSM) that covers at least 3 layers of the protocol stack, i.e., IP, TCPand Session. The state transitions for the Transmit FSM and the eventsthat cause them are discussed below.

[0671] The following summarizes the steps involved in normal fast-pathtransmit command processing:

[0672] 1) Get control of the associated CCB (gotten from the command);this involves locking the CCB to stop other processing (e.g. Receive)from altering it while this transmit processing is taking place;

[0673] 2) Get the CCB into an SRAM CCB buffer; there are 16 of thesebuffers in SRAM and they are not flushed to DRAM until the buffer spaceis needed by other CCBs. Acquisition and flushing of these CCB buffersis controlled by a hardware LRU mechanism. Thus getting the CCB into abuffer may involve flushing another CCB from its SRAM buffer;

[0674] 3) Process the SEND COMMAND (EX_SCMD) event against the CCB'sFSM.

[0675] Each event and state intersection provides an action to beexecuted and a new state. The following is an example of the state/eventtransition, the action to be executed and the new state for the SENDcommand while in transmit state IDLE (SX_IDLE): The action from thisstate/event intersection is AX_NUCMD and the next state is XMIT COMMANDACTIVE (SX_XMIT). To summarize, a command to transmit data has beenreceived while Transmit is currently idle. The action performs thefollowing steps:

[0676] 1) Store details of the command into the CCB;

[0677] 2) Check that it is OK to transmit now e.g. send window is notzero;

[0678] 3) If output is not possible, send the Check Output event toQ_EVENT1 queue for the Transmit CCB's FSM and exit;

[0679] 4) Get a DRAM 2K-byte buffer from the Q_FREEL queue into which tomove the payload data;

[0680] 5) DMA payload data from the addresses in the scatter/gatherlists in the command into an offset in the DRAM buffer that leaves spacefor the frame header; these DMAs will provide the checksum of thepayload data;

[0681] 6) Concurrently with the above DMA, fill out variable details inthe frame header template in the CCB; also get the IIP and TCP headerchecksums while doing this; note that base IP and TCP header checksumsare kept in the CCB, and these are simply updated for fields that varyper frame, viz. IP Id, IP length, IP checksum, TCP sequence and acknumbers, TCP window size, TCP flags and TCP checksum.

[0682] 7) When the payload DMA is complete, DMA the frame header fromthe CCB to the front of the DRAM buffer;

[0683] 8) Queue the DRAM buffer to the appropriate Q_UXMT queue for theinterface for this CCB;

[0684] 9) Determine if there is more payload in the command; if so, savethe current command transfer address details in the CCB and send a CHECKOUTPUT event via the Q_EVENT1 queue to the Transmit CCB; if not, sendthe ALL COMMAND DATA SENT (EX_ACDS) event to the Transmit CCB;

[0685] 10) Exit from Transmit FSM processing.

[0686] Once the INIC is handling CCBs, i.e. fast-path processing, thereare numerous other events that need to be processed apart from transmitcommands from the host for that CCB. The following are the relevantevents:

[0687] 1) New context pending (from the new context pending command);

[0688] 2) New context confirm (from that command also);

[0689] 3) Flush context request from Receive;

[0690] 4) Send data (after Check Output determines this can be done);

[0691] 5) Send an ACK (from Receive);

[0692] 6) All command data sent;

[0693] 7) Received ACK for all outstanding on a command;

[0694] 8) Persist conditions detected (WIN=0, no RTR, no PST);

[0695] 9) Context flush event detected (e.g. RTR expired);

[0696] 10) Send a window update;

[0697] 11) Persist timer expired;

[0698] 12) Check for RTR expiry;

[0699] 13) Check for PST expiry;

[0700] 14) Maybe send an ACK;

[0701] 15) Maybe update the IDLE timer;

[0702] 16) Context termination sync event received.

[0703] The following summarizes Transmit Event processing:

[0704] 1) Get control of the associated CCB; this involves locking theCCB to stop other processing (e.g. Receive) from altering it while thisprocessing is taking place.

[0705] 2) Get the CCB into an SRAM CCB buffer;

[0706] 3) If the event is “Check Output”, check whether it is nowpossible to output on this CCB; if so, process the Send Data (EX_SD)event; if not, check for other conditions e.g. all of a command's datahas been ACKed (EX_RACK), a window update is needed (EX_SWU), output isavailable but it is not possible to send (EX_WE0);

[0707] 4) If there is any event, process it against the CCB's FSM.

[0708]FIG. 20 provides a state diagram summary of the Transmit FSMstates and the main events and transitions. The state involved is thestate of the transmit path of the CCB connection. Events are generatedfrom the sources of events detailed above, and they are applied againstthe FSM giving an action to execute and a new state. The followingdiagram provides a summary of the Transmit FSM states and the mainevents and transitions.

[0709] Several Transmit details should be noted. First, regarding theslow-start algorithm that is now a part of the TCP standard will behandled on the INIC. It seems unreasonable to wait until the connectionis sending at full-rate before passing it to the INIC.

[0710] Also, the congestion algorithm will not be handled on the card.To reach congested state, the connection will have dropped frames, so itwill have flushed. The host will NOT hand out a CCB in congestionstate—it will wait until it has gotten out of that state.

[0711] A Window Probe is sent from the sending CCB to the receiving CCB,and it means the sender has the receiver in PERSIST state. Persist stateis entered when the receiver advertises a zero window. It is thus thestate of the transmitting CCB. In this state, he sends periodic windowprobes to the receiver in case an ACK from the receiver has been lost.The receiver will return his latest window size in the ACK.

[0712] A Window Update is sent from the receiving CCB to the sendingCCB, usually to tell him that the receiving window has altered. It ismostly triggered by the upper layer when it accepts some data. Thisprobably means the sending CCB is viewing the receiving CCB as being inPERSIST state.Persist state: it is planned to handle Persist timers onthe INIC. However as soon as the Persist timer completely expires, theCCB will be flushed. This means that a zero window has been advertisedfor a few seconds. A zero window would normally be a transientsituation, and would tend to happen mostly with clients that do notsupport slow-start. However it should normally reopen before the timerexpires.

[0713] The INIC code expects all transmit requests for which it has noCCB to not be greater than the MSS. If any request is, it will bedropped and an appropriate response status posted.

[0714] As a receiver, the INIC will do the right thing regarding SillyWindow avoidance and not advertise small windows—this is easy. Howeverit is necessary to also do things to avoid this as a sender, for thecases where a stupid client does advertise small windows. Withoutgetting into too much detail here, the mechanism requires the INIC codeto calculate the largest window advertisement ever advertised by theother end. It is an attempt to guess the size of the other end's receivebuffer and assumes the other end never reduces the size of its receivebuffer. See Stevens, Vol. 1 pp. 325-326.

[0715] The third processor (P2) of the integrated processors is termedthe Utility Processor. P2 performs the reset function, manages theinterface to the system, and performs the debug function. This followingpages will describe these functions in the format found in the code. Thefirst major function is reset. Second is the system interface, which iscomposed of the idle loop and associated routines. Last is the debugfunction.

[0716] Two reset functions have been implemented, a hard or cold reset,and a soft or warm reset. Power up or the occurrence of a system resetcauses hard reset. Soft reset occurs as a result of the system writing‘dead’ to location 0 of INIC memory. P2 distinguishes between these tworesets by the condition of the write pending bit in the PCI addressregister. If this bit is on, a soft reset has occurred, and PCIconfiguration space will not be set up.

[0717] One of the functions of P2 in the reset process is to load thewriteable control store (WCS) with code provided by the system. In orderto bypass this sophisticated mechanism to enable the load of code forin-circuit test, a synchronous mechanism using all three processors hasbeen designed. If bit 1 of the external options register has been set,all three processors will perform this function.

[0718] Only those functions necessary to be able to load WCS from thehost are implemented in ROM. The remaining functions implemented in ROMare subroutines that can be easily rewritten in WCS if errors arediscovered later. First of the ROM functions is the initialization ofPCI configuration space. If the EEPROM exists and is properly formatted,the data necessary to configure PCI can be found in this device. IfEEPROM does not exist, but FLASH is available and properly formatted,data to configure PCI is obtained from the FLASH memory. If neither ofthese options is available, PCI configuration space is set up using ROMdefaults. In this case bit 0 of the external options indicates that thedebug processor should be initialized. Both EEPROM and FLASH readroutines are contained in ROM, as they are required for PCIconfiguration. The FLASH read routine is fairly straightforward. TheEEPROM routines use the bit level interface of the EEPROM. Refer to theEEPROM specs to find a description of the operation of this interface.

[0719] Once PCI has been configured INIC is ready to talk to the system.At this point minimal functionality is available. The mini idle loopprovides only two functions, a branch to check status, and a branch to asmall command decode function. The mini idle loop shares the checkstatus routine with the main idle loop, and uses a very small portion ofits function. The check status routine will be described within the mainidle loop description. The command decode function supports FLASH reads,setting the interrupt status pointer, setting the status, setting themask, and writing control store.

[0720] Control store writes are done in three consecutive instructions.The first transfer is the address to be written. This transfer alsoincludes two control bits, one to indicate that this is a compare ratherthan a write, and one to indicate that at the completion of thisoperation we should jump to the start address in writeable controlstore. The second transfer is the low half of the control storeinstruction, and the third transfer is the high half.

[0721] At the completion of the load of control store P2 branches to thenewly downloaded code. Once this occurs, DRAM is initialized, and thenits size is computed. This is done by first determining itsconfiguration. By setting the addressing structure to maximum andwriting to address 1c00, the memory configuration can be computed. Ifthis write aliases to 0c00 address bit 12 is missing. If the write alsoaliases to 0400 bit 11 is missing. Once this has been determined theproper addressing structure can be initialized. Once the properaddressing configuration has been set, the size of DRAM can bedetermined using the same alias technique to determine missing highorder address bits.

[0722] The final major reset function that is performed is queueinitialization. Each queue uses 128 bytes of SRAM, and a configurableamount of DRAM, from a minimum of 1 K bytes to a maximum of 128K. Firstthe queues are initialized to the DRAM size defined by control storeconstants. Each queue begins its use of DRAM on the 128K boundaryfollowing the beginning of the previous queue, so after the queues areinitialized, a mechanism for recovering the free space between queuesthat have not been initialized to maximum size is initiated.

[0723] Two queues are allocated for use as an aid to managing localDRAM. One queue contains addresses of 256 byte blocks, and one containsaddresses of 2K blocks. The 2K queue size is determined by DRAM size,rather than a control store constant. After all queues have beeninitialized the process of allocating DRAM not used by the queues isbegun. First blocks at the end of the first queue are added to the 256byte queue until a 2K boundary is found, at which point 2K blocks areadded to the 2K queue until the beginning of the next queue is reached.This process is repeated until the DRAM located between the last andnext to last queue has been recovered. At this point the 2K queue isfilled with the remaining DRAM until the bottom address of the CCBstorage area is reached. At this point, entries are removed from the 2Kqueue in order to be split down and added to the 256-byte queue until itis close to full. In order to avoid partial tail full issues, this queueis not completely filled.

[0724] At the conclusion of queue initialization P0 and P1 are started,and P2 enters the idle loop. The idle loop is the code executed by P2when it is waiting for the next task. The purpose of the loop is tocheck all of the conditions that could initiate an operation. At thehighest level, these are:

[0725] P0 or P1 hit a debug processor installed breakpoint;

[0726] A system request has occurred over PCI;

[0727] A DMA channel has changed state;

[0728] A network interface has changed state;

[0729] A process has requested status be sent to the system;

[0730] A transmitter or receiver has stored statistics.

[0731] These functions are checked in this order. If service is requiredat any check, it is provided and the loop is begun at the beginning.Thus if the system becomes very busy, the most likely thing to finditself being serviced less is the statistics function. Service ofprocessor halts due to break points will be discussed in conjunctionwith the description of the debug processor. Service of system requestscan be broken into two major subsets. The first is system requests fromthe functional device driver, and second is system requests from thedebug driver.

[0732] The Functional Command Decode performs the requests described inthe INIC Utility Processor description. Most requests are interfacedependent. A request is made for a specific interface to perform aspecific function. As an example, PCI addresses 10, 14, 18 and 1C areused to store the pointer to the system memory location where interruptstatus should be stored for network interfaces 0, 1, 2, and 3respectively. A limited number of commands are not interface dependent,and are generally intended to be used on interface 0. These are queue areceive buffer, write control store, read eeprom, and the flash read andwrite commands.

[0733] Most of these commands simply cause a value to be stored, afterwhich P2 returns to the idle loop. If a DMA operation is requested, atthe end of the operation, status indicating the successful orunsuccessful completion of the request will be sent to the system. Thosethat initiate a DMA and generate a later status presentation are readstatistics, read PHY status, write configuration, and readconfiguration. In addition, the four transmit command buffer requests,along with the receive command buffer request cause a DMA to beperformed, but no status is required by the system after the completionof these DMA operations. The function of these operations will becovered under the idle loop DMA service discussion.

[0734] As with the functional processor, the INIC Debug Interfacedescription covers the basic function of this code. The halt, run, step,dump and load commands are all fairly straightforward and are documentedin the above referenced spec. Although break is functionally described,further explanation of the operation of this code is contained in thisdocument. The functions of the debug processor that are covered in theUtility Processor document do not require status presentation. All ofthe commands, triggered by storing a pointer in the command location, dorequire ending status to be presented.

[0735] The break function requires twelve bytes of storage for eachbreak point that is stored. Each break point can cause either one orboth processors to halt, or can simply trigger an indication that theinstruction at that location has been executed. Each break point can beexecuted a specified n times prior to halting the processor under test.When a break instruction is issued to P2, it checks to see if this isalready a break point for the other processor, and if so simply turns onthe bit to indicate both processors are using this break point. If theaddress is not presently a break point, P2 finds the next availablestorage location in SRAM for this break point information. It thenstores the address of the break point, and the contents of theinstruction at that address in the SRAM storage location. It then storesa jump instruction to the break point execution code at the location ofthe break point.

[0736] Each break point has a unique location that it jumps to in orderto quickly determine the address of the location where the replacedinstruction can be found. It also allows the processor to determine ifthis break is for it or the other potential processor under test. Thebreak point jump instruction, in addition to jumping to the break pointcode, saves the hardware status of the system. When the processor takesthis jump, it saves the remaining state required to allow it to operateindependently, and then determines if the break was intended for itself.If it was not, it builds the instruction that was replaced, restores thestate, executes the instruction and returns to the normal code. Ifhowever it determines that the break instruction was for it, it sets aflag for P2 and halts.

[0737] When P2 discovers in the idle loop that a halted processor hasset a flag, it steps the processor through the same code described abovethat it would have otherwise executed in real time. It then leaves theprocessor under test stopped in the instruction after the breakinstruction, and sends status to the system that the processor hasencountered a break point. Resetting a break point causes theinstruction to be restored to its original condition in control storeand the storage location in SRAM to be cleared.

[0738] P2 can also perform a DMA channel State Change. For the fourtransmit command buffer and the receive buffer functions, P2 will DMAthe command buffer into local memory, modify the pointer for use by thetransmit or receive processors, and add the pointer to the proper queue.This task is split into three separate functions in order to keep thisfunction operating concurrently with all other operations.

[0739] The first part of the process is the actual command decode. Asingle queue (Q_HOSTIF) is used to store requests for the four separatetransmit functions and the receive function. At command decode time twoentries are stored on Q_HOSTIF: the address of the queue that willultimately be the destination of the buffer, and the pointer to thelocation in system memory where the buffer resides.

[0740] The second part of this operation occurs when the idle loopdetects that Q_HOSTIF is not empty. A non-empty condition indicates arequest to initiate the DMA of the buffer to INIC local DRAM. When thisoccurs P2 first determines if a DMA channel is available. Channels 23-26are used for this purpose. If a channel is available, a buffer isobtained from the free queue and a DMA operation is initiated to thisbuffer. The final destination queue address and the address of the endof the buffer are stored in an SRAM location linked to this DMA channel,and P2 returns to the idle loop.

[0741] The final part of this operation occurs when it is determined inthe idle loop that the DMA operation has completed. The SRAM locationlinked to this channel contains the queue address and the data pointerto be queued. P2 obtains this data and queues the pointer, completingthe operation.

[0742] In addition to the SRAM locations used to store a description ofthe active DMA operation, four bits are used in the dma_status register.These bits are used to indicate that there has been a DMA operationinitiated on their respective channel. During part two of the aboveprocess the bit is used to determine channel availability, and is setonce a channel is acquired. During part three the bit is reset.

[0743] For tracking network interface changes, a register (link_stat) ismaintained with the current status of each of the network interfaces.When one or more of the interfaces changes status (as defined by thisregister) status is set up to notify the system of this change.

[0744] The function of the check status routine is to check to see ifany functions have requested status to be sent to the system, and tosend it if such a request has been made. The first step in this processis to reset any DMA channels that have completed a transfer. Once thishas been accomplished, P2 checks to see if there are any requests tosend new status. If there are not, P2 returns to the idle loop. If thereare requests outstanding, P2 checks to make sure that there is notanother request being serviced for that interface, or that a previouslysent status has not yet been reset by the system. If there is a requestfor service outstanding and neither of these conditions exists, anoperation to send status to the system is initiated.

[0745] The first step in this operation is to insure that if there aremultiple requests ready to be serviced they are served in a round robinfashion. Once an interface has been selected using this method P2determines if interrupts are being aggregated. If they are, the time ischecked, and if we are still within the aggregation window P2 returns tothe idle loop. If the timer has expired, P2 first checks that the hosthas not sent back the status register with the status bits we want toset already set. Although this is an unlikely occurrence, if the hostprefers to not see certain status from the INIC, this is a possiblemechanism for insuring that outcome. If this does occur, P2 returns tothe idle loop.

[0746] If this is indeed new status that has not been returned to INIC,P2 sends this status to the system. At the conclusion of this operationP2 checks to see if interrupts are masked, and returns to the idle loopif they are. If they are not, an interrupt is generated and then P2returns to the idle loop.

[0747] The flag register serves to interlock the status areas with thesystem. When status is sent to the system, a bit in the flag registercorresponding to the DMA channel used is set. This bit is not resetuntil after the system writes status back to us. Each functionalsub-processor, utility and network 0-3, has its own status area and flagregister interlock. The status areas are located sequentially in SRAM,and the bits in the flag register, for convenience, correspond to theDMA channel that is allocated to the sub-processor. The utilityprocessor uses channel 31, and the four network processors use channels30-27. Because there are only four available interrupts, networkprocessors 0 and 1 share interrupt A.

[0748] For maintaining statistics, when either a transmit or receiveprocessor completes a transfer, it posts completion status informationin the Q_STATS queue. P2 recovers these entries, analyzes them, andupdates the local statistics counters. This function is performed onlywhen no more pressing requests for P2 are outstanding.

[0749] An outbound DMA transfer generated by the INIC (a system read)can not pass a system pci write through either a host/pci or pci/pcibridge. We must, therefore, insure that we disconnect on all outboundDMA transfers so that if the system tries to write to us we won'tdeadlock. All outbound DMA operations are short, containing controldata. When one of these operations occurs, the idle loop is shortened tocheck only pci writes and the completion of the DMA of control data.However, because a pathological worst case could have the system writeto all five devices (the four network processors and the debugprocessor) context is stored for the return path and the operationoutstanding. The flags register contains five bits, one for eachprocess, indicating that this disconnected DMA operation is in progress,and five registers contain the return addresses for each of theprocesses.

[0750] The remainder of this document will describe the INIC hardwarespecification. This features an INIC peripheral component interconnect(PCI) interface which supports both 5.0V and 3.3V signalingenvironments, both 32-bit and 64 bit PCI interface, and PCI clockfrequencies from 15 MHz to 66 MHz. Other features of this interfaceinclude a high performance bus mastering architecture, host memory basedcommunications that reduce register accesses, host memory basedinterrupt status word which reduces register reads, Plug and Playcompatibility, PCI specification revision 2.1 compliance, PCI bursts ofup to 512 bytes, supports of cache line operations up to 128 bytes,supports both big-endian and little-endian byte alignments, and supportsExpansion ROM.

[0751] The INIC Network Interface includes four internal 802.3 andethernet compliant Macs, a Media Independent Interface (MII) connectableto external PHYs and supporting 10BASE-T, 100BASE-TX/FX and 100BASE-T4in full and half-duplex modes. Automatic PHY status polling notifies thesystem of status changes. SNMP statistics counters are provided,broadcast and multicast packets are handled with a promiscuous modeprovided for network monitoring or multiple unicast address detection.The interface supports huge packets of 32 KB, Mac-layer loop-back testmode, and auto-negotiating Phys.

[0752] The INIC memory features include external Dram buffering oftransrmit and receive packets, buffering configurable as 4 MB, 8 MB, 16MB or 32 MB, with a 32-bit interface that supports throughput of 224MB/s. External FLASH ROM up to 4 MB is provided, for diskless bootapplications, as well as external serial EEPROM for custom configurationand Mac addresses.

[0753] The INIC Protocol Processor includes a high speed, custom, 32-bitprocessor executing 66 million instructions per second, and processingvarious protocols with focus on IP, TCP and NETBIOS. Up to 256 residentTCP/IP contexts can be cached on the INIC for fast-path processing. Awriteable control store (WCS) allows field updates for featureenhancements.

[0754] The INIC Power includes a 3.3V chip operation and PCI controlled5.0V/3.3V I/O cell operation. Initial packaging includes 272-pin plasticball grid array, with 91 PCI signals, 68 MII signals, 58 external memorysignals, 1 clock signal and 54 signals split between power and ground.

[0755] The microprocessor is a 32-bit, full-duplex, four channel,10/100-Megabit per second (Mbps), Intelligent Network InterfaceController, designed to provide high-speed protocol processing forserver applications. It combines the functions of a standard networkinterface controller and a protocol processor within a single chip.Although designed specifically for server applications, themicroprocessor can be used by PCs, workstations and routers or anywherethat TCP/IP protocols are being utilized.

[0756] When combined with four 802.3/MII compliant Phys and SynchronousDram (SDRAM), the microprocessor provides four complete ethernet nodes.It contains four 802.3/ethernet compliant Macs, a PCI Bus Interface Unit(BIU), a memory controller, transmit FIFOs, receive FIFOs and a customTCP/IP/NETBIOS protocol processor. The microprocessor supports 10Base-T,100Base-TX, 100Base-FX and 100Base-T4 via the MII interface attachmentof appropriate Phys.

[0757] The microprocessor Macs provide statistical information that maybe used for SNMP. The Macs operate in promiscuous mode allowing themicroprocessor to function as a network monitor, receive broadcast andmulticast packets and implement multiple Mac addresses for each node.

[0758] Any 802.3/MII compliant PHY can be utilized, allowing themicroprocessor to support 10BASE-T, 10BASE-T2, 100BASE-TX, 100Base-FXand 100BASE-T4 as well as future interface standards. PHY identificationand initialization is accomplished through host driver initializationroutines. PHY status registers can be polled continuously by themicroprocessor and detected PHY status changes reported to the hostdriver. The Mac can be configured to support a maximum frame size of1518 bytes or 32768 bytes.

[0759] The 64-bit, multiplexed BIU provides a direct interface to thePCI bus for both slave and master functions. The microprocessor iscapable of operating in either a 64-bit or 32-bit PCI environment, whilesupporting 64-bit addressing in either configuration. PCI busfrequencies up to 66 MHz are supported yielding instantaneous bustransfer rates of 533 MB/s. Both 5.0V and 3.3V signaling environmentscan be utilized by the microprocessor. Configurable cache-line size upto 256B will accommodate future architectures, and Expansion ROM/Flashsupport will allow for diskless system booting. Non-PC applications aresupported via programmable big and little endian modes. Host basedcommunication has been utilized to provide the best system performancepossible.

[0760] The microprocessor supports Plug-N-Play auto-configurationthrough the PCI configuration space. External pull-up and pull-downresistors, on the memory I/O pins, allow selection of various featuresduring chip reset. Support of an external eeprom allows for localstorage of configuration information such as Mac addresses.

[0761] External SDRAM provides frame buffering, which is configurable as4 MB, 8 MB, 16 MB or 32 MB using the appropriate SIMMs. Use of −10 speedgrades yields an external buffer bandwidth of 224 MB/s. The bufferprovides temporary storage of both incoming and outgoing frames. Theprotocol processor accesses the frames within the buffer in order toimplement TCP/IP and NETBIOS. Incoming frames are processed, assembledthen transferred to host memory under the control of the protocolprocessor. For transmit, data is moved from host memory to buffers wherevarious headers are created before being transmitted out via the Mac.

[0762]FIG. 21 provides an overview of the INIC hardware.

[0763] The following Cores/Cells form the INIC: LSI Logic Ethernet-110Core, 100Base & 10Base Mac with MII interface, LSI Logic single portSRAM, triple port SRAM and ROM available, LSI Logic PCI 66 MHz, 5Vcompatible I/O cell, and LSI Logic PLL.

[0764] Table 4 outlines the INIC Die Size using an LSI Logic G10process. TABLE 4 MODULE DESCR SPEED AREA Scratch RAM, 1 K × 128 sport,4.37 ns nom., 06.77 mm² WCS, 8 K × 49 sport, 6.40 ns nom., 18.29 mm²MAP, 128 × 7 sport, 3.50 ns nom., 00.24 mm² ROM, 1 K × 49 32 col, 5.00ns nom., 00.45 mm² REGs, 512 × 32 tport, 6.10 ns nom., 03.49 mm² Macs,.75 mm² × 4 = 03.30 mm² PLL, .5 mm² = 00.55 mm² Misc. Logic 117,260gates at 5035 gates/mm²⁾ = 23.29 mm² TOTAL CORE 56.22 mm²

[0765] Table 5 outlines the INIC Pin Count, from table 4 above. TABLE 5(Core side)² = 56.22 mm² Core side = 07.50 mm Die side = core side + 1.0mm (I/O cells) = 08.50 mm Die area = 8.5 mm × 8.5 mm = 72.25 mm² Padsneeded = 220 signals × 1.25 (vss, vdd) = 275 pins LSI PBGA = 272 pins

[0766] Table 6 outlines the INIC Datapath Bandwidth TABLE 6 (12MB/s/100Base) × 2 (full duplex) × = 100 MB/s 4 connections Average framesize = 512 B Frame rate = 100 MB/s/512 B = 195,312 frames/s Cpuoverhead/frame = (256 B context read) + = 512 B/frame (64 B headerread) + (128 B context write) + (128 B misc.) Total bandwidth = (512 Bin) + (512 B out) + = 1536 B/frame (512 B Cpu) Dram Bandwidth required == 300 MB/s 1536 B/frame × 195,312 frames/s Dram Bandwidth @ 60 MHz = (32bytes/167 ns) = 202 MB/s Dram Bandwidth @ 66 MHz = (32 bytes/150 ns) =224 MB/s PCI Bandwidth required = 100 MB/s PCI Bandwidth available @ 30MHz, 32 b, average = 46 MB/s PCI Bandwidth available @ 33 MHz, 32 b,average = 50 MB/s PCI Bandwidth available @ 60 MHz, 32 b, average = 92MB/s PCI Bandwidth available @ 66 MHz, 32 b, average = 100 MB/s PCIBandwidth available @ 30 MHz, 64 b, average = 92 MB/s PCI Bandwidthavailable @ 33 MHz, 64 b, average = 100 MB/s PCI Bandwidth available @60 MHz, 64 b, average = 184 MB/s PCI Bandwidth available @ 66 MHz, 64 b,average = 200 MB/s

[0767] Table 7 outlines the INIC Cpu Bandwidth TABLE 7 Receive frameinterval = 512 B/40 MB/s = 10.24 us Instructions/frame @ 60 MHz = = 205(10.24 us/frame)/(50 ns/instruction) Instructions/frame @ 66 MHz = = 228(10.24 us/frame)/(45 ns/instruction) Required instructions/frame = 250

[0768] The following hardware features enhance LNIC performance: 512registers afford reduced scratch ram accesses and reduced instructions,register windowing eliminates context-switching overhead, separateinstruction and data paths eliminate memory contention, resident controlstore eliminates stalling during instruction fetch, multiple logicalprocessors eliminate context switching and improve real-time response,pipelined architecture increases operating frequency, shared registerand scratch ram improve inter-processor communication, fly-bystate-machine assists address compare and checksum calculation,TCP/IP-context caching reduces latency, hardware implemented queuesreduce CPU overhead and latency, horizontal microcode greatly improvesinstruction efficiency, automatic frame DMA and status between MAC andDRAM buffer, deterministic architecture coupled with context switchingeliminates processor stalls.

[0769] The INIC processor is a convenient means to provide aprogrammable state-machine which is capable of processing incomingframes, processing host commands, directing network traffic anddirecting PCI bus traffic. Three processors are implemented using sharedhardware in a three-level pipelined architecture which launches andcompletes a single instruction for every clock cycle. The instructionsare executed in three distinct phases corresponding to each of thepipeline stages where each phase is responsible for a differentfunction.

[0770] The first instruction phase writes the instruction results of thelast instruction to the destination operand, modifies the programcounter (Pc), selects the address source for the instruction to fetch,then fetches the instruction from the control store. The fetchedinstruction is then stored in the instruction register at the end of theclock cycle.

[0771] The processor instructions reside in the on-chip control-store,which is implemented as a mixture of ROM and SRAM. The ROM contains 1Kinstructions starting at address 0×0000 and aliases each 0×0400locations throughout the first 0×8000 of instruction space. The SRAM(WCS) will hold up to 0×2000 instructions starting at address 0×8000 andaliasing each 0×2000 locations throughout the last 0×8000 of instructionspace. The ROM and SRAM are both 49-bits wide accounting for bits [48:0]of the instruction microword. A separate mapping ram provides bits[55:49] of the microword (MapAddr) to allow replacement of faulty ROMbased instructions. The mapping ram has a configuration of 128×7 whichis insufficient to allow a separate map address for each of the 1K ROMlocations. To allow re-mapping of the entire 1K ROM space, the map ramaddress lines are connected to the address bits Fetch[9:3]. The resultis that the ROM is re-mapped in blocks of 8 contiguous locations.

[0772] The second instruction phase decodes the instruction which wasstored in the instruction register. It is at this point that the mapaddress is checked for a non-zero value which will cause the decoder toforce a Jmp instruction to the map address. If a non-zero value isdetected then the decoder selects the source operands for the Aluoperation based on the values of the OpdASel, OpdBSel and AluOp fields.These operands are then stored in the decode register at the end of theclock cycle. Operands may originate from File, SRAM, or flip-flop basedregisters. The second instruction phase is also where the results of theprevious instruction are written to the SRAM.

[0773] The third instruction phase is when the actual Alu operation isperformed, the test condition is selected and the Stack push and pop areimplemented. Results of the Alu operation are stored in the resultsregister at the end of the clock cycle.

[0774]FIG. 22 shows an overview of the pipelined microprocessor 470, inwhich instructions for the receive, transmit and utility processors areexecuted in three alternating phases according to Clock increments I, IIand III, the phases corresponding to each of the pipeline stages. Eachphase is responsible for different functions, and each of the threeprocessors occupies a different phase during each Clock increment. Eachprocessor usually operates upon a different instruction stream from thecontrol store 480, and each carries its own program counter and statusthrough each of the phases.

[0775] In general, a first instruction phase 500 of the pipelinedmicroprocessors completes an instruction and stores the result in adestination operand, fetches the next instruction, and stores that nextinstruction in an instruction register. A first register set 490provides a number of registers including the instruction register, and aset of controls 492 for first register set provides the controls forstorage to the first register set 490. Some items pass through the firstphase without modification by the controls 492, and instead are simplycopied into the first register set 490 or a RAM file register 533. Asecond instruction phase 560 has an instruction decoder and operandmultiplexer 498 that generally decodes the instruction that was storedin the instruction register of the first register set 490 and gathersany operands which have been generated, which are then stored in adecode register of a second register set 496. The first register set490, second register set 496 and a third register set 501, which isemployed in a third instruction phase 600, include many of the sameregisters, as will be seen in the more detailed views of FIGS. 15A-C.The instruction decoder and operand multiplexer 498 can read from twoaddress and data ports of the RAM file register 533, which operates inboth the first phase 500 and second phase 560. A third phase 600 of theprocessor 470 has an arithmetic logic unit (ALU) 602 which generallyperforms any ALU operations on the operands from the second registerset, storing the results in a results register included in the thirdregister set 501. A stack exchange 608 can reorder register stacks, anda queue manager 503 can arrange queues for the processor 470, theresults of which are stored in the third register set.

[0776] The instructions continue with the first phase then following thethird phase, as depicted by a circular pipeline 505. Note that variousfunctions have been distributed across the three phases of theinstruction execution in order to minimize the combinatorial delayswithin any given phase. With a frequency in this embodiment of 66 MHz,each Clock increment takes 15 nanoseconds to complete, for a total of 45nanoseconds to complete one instruction for each of the threeprocessors. The rotating instruction phases are depicted in more detailin FIGS. 15A-C, in which each phase is shown in a different figure.

[0777] More particularly, FIG. 23A shows some specific hardwarefunctions of the first phase 500, which generally includes the firstregister set 490 and related controls 492. The controls for the firstregister set 492 includes an SRAM control 502, which is a logicalcontrol for loading address and write data into SRAM address and dataregisters 520. Thus the output of the ALU 602 from the third phase 600may be placed by SRAM control 502 into an address register or dataregister of SRAM address and data registers 520. A load control 504similarly provides controls for writing a context for a file to filecontext register 522, and another load control 506 provides controls forstoring a variety of miscellaneous data to flip-flop registers 525. ALUcondition codes, such as whether a carried bit is set, get clocked intoALU condition codes register 528 without an operation performed in thefirst phase 500. Flag decodes 508 can perform various functions, such assetting locks, that get stored in flag registers 530.

[0778] The RAM file register 533 has a single write port for addressesand data and two read ports for addresses and data, so that more thanone register can be read from at one time. As noted above, the RAM fileregister 533 essentially straddles the first and second phases, as it iswritten in the first phase 500 and read from in the second phase 560. Acontrol store instruction 510 allows the reprogramming of the processorsdue to new data in from the control store 480, not shown in this figure,the instructions stored in an instruction register 535. The address forthis is generated in a fetch control register 511, which determineswhich address to fetch, the address stored in fetch address register538. Load control 515 provides instructions for a program counter 540,which operates much like the fetch address for the control store. Alast-in first-out stack 544 of three registers is copied to the firstregister set without undergoing other operations in this phase. Finally,a load control 517 for a debug address 548 is optionally included, whichallows correction of errors that may occur.

[0779]FIG. 23B depicts the second microprocessor phase 560, whichincludes reading addresses and data out of the RAM file register 533. Ascratch SRAM 565 is written from SRAM address and data register 520 ofthe first register set, which includes a register that passes throughthe first two phases to be incremented in the third. The scratch SRAM565 is read by the instruction decoder and operand multiplexer 498, asare most of the registers from the first register set, with theexception of the stack 544, debug address 548 and SRAM address and dataregister mentioned above. The instruction decoder and operandmultiplexer 498 looks at the various registers of set 490 and SRAM 565,decodes the instructions and gathers the operands for operation in thenext phase, in particular determining the operands to provide to the ALU602 below. The outcome of the instruction decoder and operandmultiplexer 498 is stored to a number of registers in the secondregister set 496, including ALU operands 579 and 582, ALU condition coderegister 580, and a queue channel and command 587 register, which inthis embodiment can control thirty-two queues. Several of the registersin set 496 are loaded fairly directly from the instruction register 535above without substantial decoding by the decoder 498, including aprogram control 590, a literal field 589, a test select 584 and a flagselect 585. Other registers such as the file context 522 of the firstphase 500 are always stored in a file context 577 of the second phase560, but may also be treated as an operand that is gathered by themultiplexer 572. The stack registers 544 are simply copied in stackregister 594. The program counter 540 is incremented 568 in this phaseand stored in register 592. Also incremented 570 is the optional debugaddress 548, and a load control 575 may be fed from the pipeline 505 atthis point in order to allow error control in each phase, the resultstored in debug address 598.

[0780]FIG. 23C depicts the third microprocessor phase 600, whichincludes ALU and queue operations. The ALU 602 includes an adder,priority encoders and other standard logic functions. Results of the ALUare stored in registers ALU output 618, ALU condition codes 620 anddestination operand results 622. A file context register 616, flagselect register 626 and literal field register 630 are simply copiedfrom the previous phase 560. A test multiplexer 604 is provided todetermine whether a conditional jump results in a jump, with the resultsstored in a test results register 624. The test multiplexer 604 mayinstead be performed in the first phase 500 along with similar decisionssuch as fetch control 511. A stack exchange 608 shifts a stack up ordown by fetching a program counter from stack 594 or putting a programcounter onto that stack, results of which are stored in program control634, program counter 638 and stack 640 registers. The SRAM address mayoptionally be incremented in this phase 600. Another load control 610for another debug address 642 may be forced from the pipeline 505 atthis point in order to allow error control in this phase also. A QRAM &QALU 606, shown together in this figure, read from the queue channel andcommand register 587, store in SRAM and rearrange queues, adding orremoving data and pointers as needed to manage the queues of data,sending results to the test multiplexer 604 and a queue flags and queueaddress register 628. Thus the QRAM & QALU 606 assume the duties ofmanaging queues for the three processors, a task conventionallyperformed sequentially by software on a CPU, the queue manager 606instead providing accelerated and substantially parallel hardwarequeuing.

[0781] The micro-instructions are divided into six types according tothe program control directive. The micro-instruction is further dividedinto sub-fields for which the definitions are dependent upon theinstruction type. The word format for the six instruction types arelisted in Table 8 below. TABLE 8 TYPE _[55:49]_(—) [48:47] [46:42]_[41:33]_(—) _[32:24]_(—) [23:16] [15:00] Jcc 0b0000000 0b00, AluOp,OpdASel, OpdBSel, TstSel, Literal Jmp 0b0000000 0b01, AluOp, OpdASel,OpdBSel, FlgSel, Literal Jsr 0b0000000 0b10, AluOp, OpdASel, OpdBSel,FlgSel, Literal Rts 0b0000000 0b11, AluOp, OpdASel, OpdBSel, 0hff,Literal Nxt 0b0000000 0b11, AluOp, OpdASel, OpdBSel, FlgSel, Literal MapMapAddr 0bXX, 0bXXXXX, 0bXXXXXXXXX, 0bXXXXXXXXX, 0hXX, 0hXXXX

[0782] All instructions include the Alu operation (AluOp), operand “A”select (OpdASel), operand “B” select (OpdBSel) and Literal fields. Otherfield usage depends upon the instruction type.

[0783] The “jump condition code” (Jcc) instruction causes the programcounter to be altered if the condition selected by the “test select”(TstSel) field is asserted. The new program counter (Pc) value is loadedfrom either the Literal field or the AluOut as described in thefollowing section and the Literal field may be used as a source for theAlu or the ram address if the new Pc value is sourced by the Alu.

[0784] The “jump” (Jmp) instruction causes the program counter to bealtered unconditionally. The new program counter (Pc) value is loadedfrom either the Literal field or the AluOut as described in thefollowing section. The format allows instruction bits 23:16 to be usedto perform a flag operation and the Literal field may be used as asource for the Alu or the ram address if the new Pc value is sourced bythe Alu.

[0785] The “jump subroutine” (Jsr) instruction causes the programcounter to be altered unconditionally. The new program counter (Pc)value is loaded from either the Literal field or the AluOut as describedin the following section. The old program counter value is stored on thetop location of the Pc-Stack which is implemented as a LIFO memory. Theformat allows instruction bits 23:16 to be used to perform a flagoperation and the Literal field may be used as a source for the Alu orthe ram address if the new Pc value is sourced by the Alu.

[0786] The “Nxt” (Nxt) instruction causes the program counter toincrement. The format allows instruction bits 23:16 to be used toperform a flag operation and the Literal field may be used as a sourcefor the Alu or the ram address.

[0787] The “return from subroutine” (Rts) instruction is a special formof the Nxt instruction in which the “flag operation” (FlgSel) field isset to a value of 0hff. The current Pc value is replaced with the lastvalue stored in the stack. The Literal field may be used as a source forthe Alu or the ram address.

[0788] The Map instruction is provided to allow replacement ofinstructions which have been stored in ROM and is implemented any timethe “map enable” (MapEn) bit has been set and the content of the “mapaddress” (MapAddr) field is non-zero. The instruction decoder forces ajump instruction with the Alu operation and destination fields set topass the MapAddr field to the program control block.

[0789] The program control is determined by a combination of PgmCtrl,DstOpd, FlgSel and TstSel. The behavior of the program control isillustrated in the “C-like” description contained in CD Appendix A.

[0790] Hardware will detect certain program errors. Any sequencergenerating a program error will be forced to continue executing fromlocation 0004. The program errors detected are:

[0791] 1. Stack Overflow—A JSR is attempted and the stack registers arefull.

[0792] 2. Stack Underflow—An RTS is attempted and the stack registersare empty.

[0793] 3. Incompatible SRAM Size & SRAM Alignment—An SRAM Operation isattempted where the size and the SRAM address would cause the operationto extend beyond the size of the word, e.g. Size=4 Address=401 or Size=2Address=563

[0794] 4. A SRAM read is attempted immediately following an SRAM write.Because an SRAM write is actually done in the clock cycle of thefollowing instruction, the SRAM interface will be busy during thatphase, and an SRAM read is illegal at this time.

[0795] Sequencer behavior is described with in CD Appendix A.

[0796]FIG. 24 is a diagram of various sequencers contained in the INICwith arrows representing the flow of data therebetween. Requestinformation such as r/w, address, size, endian and alignment arerepresented by each request line. Acknowledge information to mastersequencers include only the size of the transfer being acknowledged.

[0797]FIG. 25 illustrates how data movement is accomplished for a Pcislave write to Dram. Note that the Psi (Pci slave in) module functionsas both a master sequencer. Psi sends a write request to the SramCtrlmodule. Psi requests Xwr to move data from SRAM to dram. Xwrsubsequently sends a read request to the SRAMCtrl module then writes thedata to the dram via the Xctrl module. As each piece of data is movedfrom the SRAM to Xwr, Xwr sends an acknowledge to the Psi module.

[0798]FIG. 26 is a diagram of an SRAM CONTROL SEQUENCER (SramCtrl). SRAMis the nexus for data movement within the microprocessor. A hierarchy ofsequencers, working in concert, accomplish the movement of data betweenDRAM, SRAM, Cpu, ethernet and the Pci bus. Slave sequencers, providedwith stimulus from master sequencers, request data movement operationsby way of the SRAM, Pci bus, DRAM and Flash. The slave sequencersprioritize, service and acknowledge the requests.

[0799] The SRAM control sequencer services requests to store to, orretrieve data from an SRAM organized as 1024 locations by 128 bits (16KB). The sequencer operates at a frequency of 133 MHz, allowing both aCpu access and a DMA access to occur during a standard 66 MHz Cpu cycle.One 133 MHz cycle is reserved for Cpu accesses during each 66 MHz cyclewhile the remaining 133 MHz cycle is reserved for DMA accesses on aprioritized basis.

[0800]FIG. 26 shows the major functions of the SRAM control sequencer. Aslave sequencer begins by asserting a request along with r/w, ramaddress, endian, data path size, data path alignment and request size.SramCtrl prioritizes the requests. The request parameters are thenselected by a multiplexer which feeds the parameters to the SRAM via aregister. The requester provides the SRAM address which when coupledwith the other parameters controls the input and output alignment. SRAMoutputs are fed to the output aligner via a register. Requests areacknowledged in parallel with the returned data. FIG. 27 is a timingdiagram depicting two ram accesses during a single 66 MHz clock cycle.

[0801]FIG. 28 is a diagram of an EXTERNAL MEMORY CONTROL (Xctrl). Xctrlprovides the facility whereby Xwr, Xrd, Dcfg and Eectrl access externalFlash and DRAM. Xctrl includes an arbiter, i/o registers, datamultiplexers, address multiplexers and control multiplexers. Ownershipof the external memory interface is requested by each block and grantedto each of the requesters by the arbiter function. Once ownership hasbeen granted the multiplexers select the address, data and controlsignals from owner, allowing access to external memory.

[0802]FIG. 30 is a diagram of an EXTERNAL MEMORY READ SEQUENCER (Xrd).The Xrd sequencer acts only as a slave sequencer. Servicing requestsissued by master sequencers, the Xrd sequencer moves data from externalSDRAM or flash to the SRAM, via the Xctrl module, in blocks of 32 bytesor less. The nature of the SDRAM requires fixed burst sizes for each ofit's internal banks with ras precharge intervals between each access. Byselecting a burst size of 32 bytes for SDRAM reads and interleaving bankaccesses on a 16 byte boundary, we can ensure that the ras prechargeinterval for the first bank is satisfied before burst completion for thesecond bank, allowing us to re-instruct the first bank and continue withuninterrupted DRAM access. SDRAMs require a consistent burst size beutilized each and every time the SDRAM is accessed. For this reason, ifan SDRAM access does not begin or end on a 32 byte boundary, SDRAMbandwidth will be reduced due to less than 32 bytes of data beingtransferred during the burst cycle.

[0803] A first step in servicing a request to move data from SDRAM toSRAM is the prioritization of the master sequencer requests. Next theXrd sequencer takes a snapshot of the DRAM read address and appliesconfiguration information to determine the correct bank, row and columnaddress to apply. Once sufficient data has been read, the Xrd sequencerissues a write request to the SramCtrl sequencer which in turn sends anacknowledge to the Xrd sequencer. The Xrd sequencer passes theacknowledge along to the level two master with a size code indicatinghow much data was written during the SRAM cycle allowing the update ofpointers and counters. The DRAM read and SRAM write cycles repeat untilthe original burst request has been completed at which point the Xrdsequencer prioritizes any remaining requests in preparation for the nextburst cycle.

[0804] Contiguous DRAM burst cycles are not guaranteed to the Xrdsequencer as an algorithm is implemented which ensures highest priorityto refresh cycles followed by flash accesses, DRAM writes then DRAMreads.

[0805]FIG. 29 is a timing diagram illustrating how data is read fromSDRAM. The DRAM has been configured for a burst of four with a latencyof two clock cycles. Bank A is first selected/activated followed by aread command two clock cycles later. The bank select/activate for bank Bis next issued as read data begins returning two clocks after the readcommand was issued to bank A. Two clock cycles before we need to receivedata from bank B we issue the read command. Once all 16 bytes have beenreceived from bank A we begin receiving data from bank B.

[0806]FIG. 32 depicts the major functional blocks of the EXTERNAL MEMORYWRITE SEQUENCER (Xwr). The Xwr sequencer is a slave sequencer. Servicingrequests issued by master sequencers, the Xwr sequencer moves data fromSRAM to the external SDRAM or flash, via the Xctrl module, in blocks of32 bytes or less while accumulating a checksum of the data moved. Thenature of the SDRAM requires fixed burst sizes for each of its internalbanks with ras precharge intervals between each access. By selecting aburst size of 32 bytes for SDRAM writes and interleaving bank accesseson a 16 byte boundary, we can ensure that the ras precharge interval forthe first bank is satisfied before burst completion for the second bank,allowing us to re-instruct the first bank and continue withuninterrupted DRAM access. SDRAMs require a consistent burst size beutilized each and every time the SDRAM is accessed. For this reason, ifan SDRAM access does not begin or end on a 32-byte boundary, SDRAMbandwidth will be reduced due to less than 32 bytes of data beingtransferred during the burst cycle.

[0807] The first step in servicing a request to move data from SRAM toSDRAM is the prioritization of the level two master requests. Next theXwr sequencer takes a Snapshot of the DRAM write address and appliesconfiguration information to determine the correct DRAM, bank, row andcolumn address to apply. The Xwr sequencer immediately issues a readcommand to the SRAM to which the SRAM responds with both data and anacknowledge. The Xwr sequencer passes the acknowledge to the level twomaster along with a size code indicating how much data was read duringthe SRAM cycle allowing the update of pointers and counters. Oncesufficient data has been read from SRAM, the Xwr sequencer issues awrite command to the DRAM starting the burst cycle and computing achecksum as the data flies by. The SRAM read cycle repeats until theoriginal burst request has been completed at which point the Xwrsequencer prioritizes any remaining requests in preparation for the nextburst cycle.

[0808] Contiguous DRAM burst cycles are not guaranteed to the Xwrsequencer as an algorithm is implemented which ensures highest priorityto refresh cycles followed by flash accesses then DRAM writes.

[0809]FIG. 31 is a timing diagram illustrating how data is written toSDRAM. The DRAM has been configured for a burst of four with a latencyof two clock cycles. Bank A is first selected/activated followed by awrite command two clock cycles later. The bank select/activate for bankB is next issued in preparation for issuing the second write command. Assoon as the first 16 byte burst to bank A completes we issue the writecommand for bank B and begin supplying data.

[0810] A PCI MASTER-OUT SEQUENCER (Pmo) is shown in FIG. 33. The Pmosequencer acts only as a slave sequencer. Servicing requests issued bymaster sequencers, the Pmo sequencer moves data from an SRAM based FIFOto a PCI target, via the PciMstrIO module, in bursts of up to 256 bytes.The nature of the PCI bus dictates the use of the write line command toensure optimal system performance. The write line command requires thatthe Pmo sequencer be capable of transferring a whole multiple (1×, 2×,3×, . . . ) of cache lines of which the size is set through the PCIconfiguration registers. To accomplish this end, Pmo will automaticallyperform partial bursts until it has aligned the transfers on a cacheline boundary at which time it will begin usage of the write linecommand. The SRAM FIFO depth, of 256 bytes, has been chosen in order toallow Pmo to accommodate cache line sizes up to 128 bytes. Provided thecache line size is less than 128 bytes, Pmo will perform multiple,contiguous cache line bursts until it has exhausted the supply of data.

[0811] Pmo receives requests from two separate sources; the DRAM to PCI(D2p) module and the SRAM to PCI (S2p) module. An operation first beginswith prioritization of the requests where the S2p module is givenhighest priority. Next, the Pmo module takes a Snapshot of the SRAM FIFOaddress and uses this to generate read requests for the SramCtrlsequencer. The Pmo module then proceeds to arbitrate for ownership ofthe PCI bus via the PciMstrIO module. Once the Pmo holding registershave sufficient data and PCI bus mastership has been granted, the Pmomodule begins transferring data to the PCI target. For each successfultransfer, Pmo sends an acknowledge and encoded size to the mastersequencer, allow it to update it's internal pointers, counters andstatus. Once the PCI burst transaction has terminated, Pmo parks on thePCI bus unless another initiator has requested ownership. Pmo againprioritizes the incoming requests and repeats the process.

[0812]FIG. 34 is a diagram of a PCI MASTER-IN SEQUENCER (Pmi). The Pmisequencer acts only as a slave sequencer. Servicing requests issued bymaster sequencers, the Pmi sequencer moves data from a PCI target to anSRAM based FIFO, via the PciMstrIO module, in bursts of up to 256 bytes.The nature of the PCI bus dictates the use of the read multiple commandto ensure optimal system performance. The read multiple command requiresthat the Pmi sequencer be capable of transferring a cache line or moreof data. To accomplish this end, Pmi will automatically perform partialcache line bursts until it has aligned the transfers on a cache lineboundary at which time it will begin usage of the read multiple command.The SRAM FIFO depth, of 256 bytes, has been chosen in order to allow Pmito accommodate cache line sizes up to 128 bytes. Provided the cache linesize is less than 128 bytes, Pmi will perform multiple, contiguous cacheline bursts until it has filled the FIFO.

[0813] Pmi receive requests from two separate sources; the PCI to DRAM(P2d) module and the PCI to SRAM (P2s) module. An operation first beginswith prioritization of the requests where the P2s module is givenhighest priority. The Pmi module then proceeds to arbitrate forownership of the PCI bus via the PciMstrIO module. Once the PCI busmastership has been granted and the Pmi holding registers havesufficient data, the Pmi module begins transferring data to the SRAMFIFO. For each successful transfer, Pmi sends an acknowledge and encodedsize to the master sequencer, allowing it to update it's internalpointers, counters and status. Once the PCI burst transaction hasterminated, Pmi parks on the PCI bus unless another initiator hasrequested ownership. Pmi again prioritizes the incoming requests andrepeats the process.

[0814]FIG. 36 is a diagram of a DRAM TO PCI SEQUENCER (D2p). The D2psequencer acts as a master sequencer. Servicing channel requests issuedby the Cpu, the D2p sequencer manages movement of data from DRAM to thePCI bus by issuing requests to both the Xrd sequencer and the Pmosequencer. Data transfer is accomplished using an SRAM based FIFOthrough which data is staged.

[0815] D2p can receive requests from any of the processor's thirty-twoDMA channels. Once a command request has been detected, D2p fetches aDMA descriptor from an SRAM location dedicated to the requesting channelwhich includes the DRAM address, PCI address, PCI endian and requestsize. D2p then issues a request to the D2s sequencer causing the SRAMbased FIFO to fill with DRAM data. Once the FIFO contains sufficientdata for a PCI transaction, D2s issues a request to Pmo which in turnmoves data from the FIFO to a PCI target. The process repeats until theentire request has been satisfied at which time D2p writes ending statusin to the SRAM DMA descriptor area and sets the channel done bitassociated with that channel. D2p then monitors the DMA channels foradditional requests.

[0816]FIG. 35 is an illustration showing the major blocks involved inthe movement of data from DRAM to PCI target.

[0817]FIG. 38 is a diagram of a PCI TO DRAM SEQUENCER (P2d). The P2dsequencer acts as both a slave sequencer and a master sequencer.Servicing channel requests issued by the Cpu, the P2d sequencer managesmovement of data from PCI bus to DRAM by issuing requests to both theXwr sequencer and the Pmi sequencer. Data transfer is accomplished usingan SRAM based FIFO through which data is staged.

[0818] P2d can receive requests from any of the processor's thirty-twoDMA channels. Once a command request has been detected, P2d, operatingas a slave sequencer, fetches a DMA descriptor from an SRAM locationdedicated to the requesting channel which includes the DRAM address, PCIaddress, PCI endian and request size. P2d then issues a request to Pmowhich in turn moves data from the PCI target to the SRAM FIFO. Next, P2dissues a request to the Xwr sequencer causing the SRAM based FIFOcontents to be written to the DRAM. The process repeats until the entirerequest has been satisfied at which time P2d writes ending status in tothe SRAM DMA descriptor area and sets the channel done bit associatedwith that channel. P2d then monitors the DMA channels for additionalrequests.

[0819]FIG. 37 is an illustration showing the major blocks involved inthe movement of data from a PCI target to DRAM.

[0820]FIG. 40 is a diagram of a SRAM TO PCI SEQUENCER (S2p). The S2psequencer acts as both a slave sequencer and a master sequencer.Servicing channel requests issued by the Cpu, the S2p sequencer managesmovement of data from SRAM to the PCI bus by issuing requests to the Pmosequencer.

[0821] S2p can receive requests from any of the processor's thirty-twoDMA channels. Once a command request has been detected, S2p, operatingas a slave sequencer, fetches a DMA descriptor from an SRAM locationdedicated to the requesting channel which includes the SRAM address, PCIaddress, PCI endian and request size. S2p then issues a request to Pmowhich in turn moves data from the SRAM to a PCI target. The processrepeats until the entire request has been satisfied at which time S2pwrites ending status in to the SRAM DMA descriptor area and sets thechannel done bit associated with that channel. S2p then monitors the DMAchannels for additional requests.

[0822]FIG. 39 is an illustration showing the major blocks involved inthe movement of data from SRAM to PCI target.

[0823]FIG. 42 is a diagram of a PCI TO SRAM SEQUENCER (P2s). The P2ssequencer acts as both a slave sequencer and a master sequencer.Servicing channel requests issued by the Cpu, the P2s sequencer managesmovement of data from PCI bus to SRAM by issuing requests to the Pmisequencer.

[0824] P2s can receive requests from any of the processor's thirty-twoDMA channels. Once a command request has been detected, P2s, operatingas a slave sequencer, fetches a DMA descriptor from an SRAM locationdedicated to the requesting channel which includes the SRAM address, PCIaddress, PCI endian and request size. P2s then issues a request to Pmowhich in turn moves data from the PCI target to the SRAM. The processrepeats until the entire request has been satisfied at which time P2swrites ending status in to the DMA descriptor area of SRAM and sets thechannel done bit associated with that channel. P2s then monitors the DMAchannels for additional requests.

[0825]FIG. 41 is an illustration showing the major blocks involved inthe movement of data from a PCI target to DRAM.

[0826]FIG. 44 is a diagram of a DRAM TO SRAM SEQUENCER (D2s). The D2ssequencer acts as both a slave sequencer and a master sequencer.Servicing channel requests issued by the Cpu, the D2s sequencer managesmovement of data from DRAM to SRAM by issuing requests to the Xrdsequencer.

[0827] D2s can receive requests from any of the processor's thirty-twoDMA channels. Once a command request has been detected, D2s, operatingas a slave sequencer, fetches a DMA descriptor from an SRAM locationdedicated to the requesting channel which includes the DRAM address,SRAM address and request size. D2s then issues a request to the Xrdsequencer causing the transfer of data to the SRAM. The process repeatsuntil the entire request has been satisfied at which time D2s writesending status in to the SRAM DMA descriptor area and sets the channeldone bit associated with that channel. D2s then monitors the DMAchannels for additional requests.

[0828]FIG. 43 is an illustration showing the major blocks involved inthe movement of data from DRAM to SRAM.

[0829]FIG. 46 is a diagram of a SRAM TO DRAM SEQUENCER (S2d). The S2dsequencer acts as both a slave sequencer and a master sequencer.Servicing channel requests issued by the Cpu, the S2d sequencer managesmovement of data from SRAM to DRAM by issuing requests to the Xwrsequencer.

[0830] S2d can receive requests from any of the processor's thirty-twoDMA channels. Once a command request has been detected, S2d, operatingas a slave sequencer, fetches a DMA descriptor from an SRAM locationdedicated to the requesting channel which includes the DRAM address,SRAM address, checksum reset and request size. S2d then issues a requestto the Xwr sequencer causing the transfer of data to the DRAM. Theprocess repeats until the entire request has been satisfied at whichtime S2d writes ending status in to the SRAM DMA descriptor area andsets the channel done bit associated with that channel. S2d thenmonitors the DMA channels for additional requests.

[0831]FIG. 45 is an illustration showing the major blocks involved inthe movement of data from SRAM to DRAM. FIG. 47 depicts a sequence ofevents when a PCI SLAVE INPUT SEQUENCER (Psi) is the target of a PCIwrite operation. The Psi sequencer acts as both a slave sequencer and amaster sequencer. Servicing requests issued by a PCI master, the Psisequencer manages movement of data from PCI bus to SRAM and PCI bus toDRAM via SRAM by issuing requests to the SramCtrl and Xwr sequencers.

[0832] Psi manages write requests to configuration space, expansion rom,DRAM, SRAM and memory mapped registers. Psi separates these PCI busoperations in to two categories with different action taken for each.DRAM accesses result in Psi generating write request to an SRAM bufferfollowed with a write request to the Xwr sequencer. Subsequent write orread DRAM operations are retry terminated until the buffer has beenemptied. An event notification is set for the processor allowing messagepassing to occur through DRAM space.

[0833] All other PCI write transactions result in Psi posting the writeinformation including PCI address, PCI byte marks and PCI data to areserved location in SRAM, then setting an event flag which the eventprocessor monitors. Subsequent writes or reads of configuration,expansion rom, SRAM or registers are terminated with retry until theprocessor clears the event flag. This allows SiMBa to keep pipelininglevels to a minimum for the posted write and give the processor ampletime to modify data for subsequent PCI read operations. Note that events4 through 7 occur only when the write operation targets the DRAM.

[0834]FIG. 48 depicts the sequence of events when a PCI SLAVE OUTPUTSEQUENCER (Pso) is the target of a PCI read operation. The Pso sequenceracts as both a slave sequencer and a master sequencer. Servicingrequests issued by a PCI master, the Pso sequencer manages movement ofdata to PCI bus form SRAM and to PCI bus from DRAM via SRAM by issuingrequests to the SramCtrl and Xrd sequencers.

[0835] Pso manages read requests to configuration space, expansion rom,DRAM, SRAM and memory mapped registers. Pso separates these PCI busoperations in to two categories with different action taken for each.DRAM accesses result in Pso generating read request to the Xrd sequencerfollowed with a read request to SRAM buffer. Subsequent write or readDRAM operations are retry terminated until the buffer has been emptied.

[0836] All other PCI read transactions result in Pso posting the readrequest information including PCI address and PCI byte marks to areserved location in SRAM, then setting an event flag which the eventprocessor monitors. Subsequent writes or reads of configuration,expansion rom, SRAM or registers are terminated with retry until theprocessor clears the event flag. This allows SiMBa to use a microcodedresponse mechanism to return data for the request. The processor decodesthe request information, formulates or fetches the requested data andstores it in SRAM then clears the event flag allowing Pso to fetch thedata and return it on the PCI bus.

[0837]FIG. 50 is a diagram of a FRAME RECEIVE SEQUENCER (RcvX). Thereceive sequencer (RcvSeq) analyzes and manages incoming packets, storesthe result in DRAM buffers, then notifies the processor through thereceive queue (RcvQ) mechanism. The process begins when a bufferdescriptor is available at the output of the FreeQ. RcvSeq issues arequest to the Qmg which responds by supplying the buffer descriptor toRcvSeq. RcvSeq then waits for a receive packet. The Mac, network,transport and session information is analyzed as each byte is receivedand stored in the assembly register (AssyReg). When four bytes ofinformation is available, RcvSeq requests a write of the data to theSRAM. When sufficient data has been stored in the SRAM based receiveFIFO, a DRAM write request is issued to Xwr. The process continues untilthe entire packet has been received at which point RcvSeq stores theresults of the packet analysis in the beginning of the DRAM buffer. Oncethe buffer and status have both been stored, RcvSeq issues a write-queuerequest to Qmg. Qmg responds by storing a buffer descriptor and a statusvector provided by RcvSeq. The process then repeats. If RcvSeq detectsthe arrival of a packet before a free buffer is available, it ignoresthe packet and sets the FrameLost status bit for the next receivedpacket.

[0838]FIG. 49 depicts a sequence of events for successful reception of apacket followed by a definition of the receive buffer and the bufferdescriptor as stored on the RcvQ.

[0839] CD Appendix B defines various bits of control informationrelating to receive packets.

[0840]FIG. 52 is a diagram of a FRAME TRANSMIT SEQUENCER (XmtX). Thetransmit sequencer (XmtSeq) analyzes and manages outgoing packets, usingbuffer descriptors retrieved from the transmit queue (XmtQ) then storingthe descriptor for the freed buffer in the free buffer queue (FreeQ).The process begins when a buffer descriptor is available at the outputof the XmtQ. XmtSeq issues a request to the Qmg which responds bysupplying the buffer descriptor to XmtSeq. XmtSeq then issues a readrequest to the Xrd sequencer. Next, XmtSeq issues a read request toSramCtrl then instructs the Mac to begin frame transmission. Once theframe transmission has completed, XmtSeq stores the buffer descriptor onthe FreeQ thereby recycling the buffer.

[0841]FIG. 51 depicts a sequence of events for successful transmissionof a packet followed by a definition of the receive buffer and thebuffer descriptor as stored on the XmtQ.

[0842] CD Appendix C defines various bits of control informationrelating to transmit packets.

[0843]FIG. 54 is a diagram of a QUEUE MANAGER (Qmg). The INIC includesspecial hardware assist for the implementation of message and pointerqueues. The hardware assist is called the queue manager (Qmg) andmanages the movement of queue entries between Cpu and SRAM, between DMAsequencers and SRAM as well as between SRAM and DRAM. Queues comprisethree distinct entities; the queue head (QHd), the queue tail (QTI) andthe queue body (QBdy). QHd resides in 64 bytes of scratch ram andprovides the area to which entries will be written (pushed). QTl residesin 64 bytes of scratch ram and contains queue locations from whichentries will be read (popped). QBdy resides in DRAM and containslocations for expansion of the queue in order to minimize the SRAM spacerequirements. The QBdy size depends upon the queue being accessed andthe initialization parameters presented during queue initialization.

[0844]FIG. 53 is a timing diagram for the Qmg, which accepts operationsfrom both Cpu and DMA sources. Executing these operations at a frequencyof 133 MHz, Qmg reserves even cycles for DMA requests and reserves oddcycles for Cpu requests. Valid Cpu operations include initialize queue(InitQ), write queue (WrQ) and read queue (RdQ). Valid DMA requestsinclude read body (RdBdy) and write body (WrBdy). Qmg working in unisonwith Q2d and D2q generate requests to the Xwr and Xrd sequencers tocontrol the movement of data between the QHd, QTI and QBdy.

[0845] The arbiter selects the next operation to be performed. Thedual-ported SRAM holds the queue variables HdWrAddr, HdRdAddr, TlWrAddr,TlRdAddr, BdyWrAddr, BdyRdAddr and QSz. Qmg accepts an operationrequest, fetches the queue variables from the queue ram (Qram), modifiesthe variables based on the current state and the requested operationthen updates the variables and issues a read or write request to theSRAM controller. The SRAM controller services the requests by writingthe tail or reading the head and returning an acknowledge.

[0846] DMA operations are accomplished through a combination ofthirtytwo DMA channels (DmaCh) and seven DMA sequencers (DmaSeq). EachDMA channel provides a mechanism whereby a Cpu can issue a command toany of the seven DMA sequencers. Whereas the DMA channels aremulti-purpose, the DMA sequencers they command are single purpose asfollows.

[0847] Table 9 lists functions of the DMA sequencers. TABLE 9 DMA SEQ #NAME DESCRIPTION 0 none This is a no operation address. 1 D2dSeq Movesdata from ExtMem to ExtMem. 2 D2sSeq Moves data from ExtMem bus to SRAM.3 D2pSeq Moves data from ExtMem to PCI bus. 4 S2dSeq Moves data fromSRAM to ExtMem. 5 S2pSeq Moves data from SRAM to PCI bus. 6 P2dSeq Movesdata from PCI bus to ExtMem. 7 P2sSeq Moves data from PCI bus to SRAM.

[0848] The processors manage DMA in the following way. The processorwrites a DMA descriptor to an SRAM location reserved for the DMAchannel. The format of the DMA descriptor is dependent upon the targetedDMA sequencer. The processor then writes the DMA sequencer number to thechannel command register.

[0849] Each of the DMA sequencers polls all thirty two DMA channels insearch of commands to execute. Once a command request has been detected,the DMA sequencer fetches a DMA descriptor from a fixed location inSRAM. The SRAM location is fixed and is determined by the DMA channelnumber. The DMA sequencer loads the DMA descriptor into its ownregisters, executes the command, then overwrites the DMA descriptor withending status. Once the command has halted, due to completion or error,and the ending status has been written, the DMA sequencer sets the donebit for the current DMA channel.

[0850] The done bit appears in a DMA event register which the Cpu canexamine. The Cpu fetches ending status from SRAM, then clears the donebit by writing zeroes to the channel command (ChCmd) register. Thechannel is now ready to accept another command.

[0851] CD Appendix D defines various bits of control informationrelating to DMA operations.

1. A method for communication involving a computer having a memory, anetwork, and a network interface device that is coupled between thecomputer and the network, the method comprising: running an applicationon the computer corresponding to a Transport Control Protocol (TCP)connection with a remote host, the TCP connection maintained by thenetwork interface device; and advertising to the remote host, by the TCPconnection on the network interface device, a receive window of space inthe memory that corresponds to the TCP connection and is available tostore data for the application.
 2. The method of claim 1, furthercomprising: accepting the data by the application; and transmitting,from the computer to the network interface device, window updateinformation.
 3. The method of claim 2, further comprising: updating thereceive window advertised by the network interface device, based uponthe window update information.
 4. The method of claim 2, furthercomprising: creating a window update command containing the windowupdate information, prior to transmitting window update information. 5.The method of claim 2, further comprising: piggybacking the windowupdate information on other information being transmitted from the hostcomputer to the network interface device.
 6. The method of claim 1,further comprising: signaling by the computer that the data has beenaccepted by the application; and updating the receive window advertisedby the network interface device.
 7. The method of claim 1, furthercomprising: accumulating window update information by the computer; andsending the window update information from the computer to the networkinterface device.
 8. The method of claim 1, further comprising: settinga threshold level of bytes to be consumed by the application; andtransmitting window update information from the computer to the networkinterface device when the threshold level is exceeded.
 9. The method ofclaim 8, further comprising: creating, by the computer, a window updatecommand containing the window update information, prior to transmittingthe window update information.
 10. The method of claim 1, furthercomprising: transmitting additional information from the application tothe network interface device; and piggybacking the window updateinformation on the additional information.
 11. The method of claim 1,further comprising: transmitting a scatter/gather list for theapplication, from the computer to the network interface device, alongwith the receive window update.
 12. The method of claim 1, furthercomprising: receiving, by the network interface device from the network,at least one packet containing the data; processing a TCP header of thepacket by the network interface device; and storing the data in thespace in the memory that corresponds to the TCP connection.
 13. Themethod of claim 1, further comprising: receiving, by the networkinterface device from the network, at least one packet containing thedata; processing a TCP header of the packet by the network interfacedevice; and storing the data in a portion of the memory that iscontrolled by the application, including bypassing the space in thememory that corresponds to the TCP connection.
 14. The method of claimZ, further comprising: sending the data directly to the application,including bypassing the space in the memory that corresponds to the TCPconnection; and maintaining the receive window unchanged to reflect thedata sent directly to the application.
 15. The method of claim 1,further comprising: accumulating, by the computer, a count of the datathat has been accepted by the application from the space in the memorythat corresponds to the TCP connection; and using the count to updatethe receive window.
 16. A method for communication between a computerhaving a memory, a network, and a network interface device that iscoupled between the computer and the network, the method comprising:running an application on the computer corresponding to a TransportControl Protocol (TCP) connection maintained by the network interfacedevice; and transmitting, from the computer to the network interfacedevice, update information for a receive window of space in the memorythat corresponds to the TCP connection and is available to store datareceived from the network for the application.
 17. The method of claim16, further comprising advertising, by the network interface device, thereceive window to the network.
 18. The method of claim 17, furthercomprising updating the receive window advertised by the networkinterface device, based upon the update information for the receivewindow.
 19. The method of claim 16, wherein the transmitting updateinformation occurs in response to accepting the data by the application.20. The method of claim 16, further comprising: creating a window updatecommand containing the update information for the receive window, priorto transmitting the update information for the receive window.
 21. Themethod of claim 16, further comprising: piggybacking the updateinformation for the receive window on other information beingtransmitted from the computer to the network interface device.
 22. Themethod of claim 16, further comprising: setting a threshold level ofbytes to be consumed by the application; and transmitting the updateinformation for the receive window from the computer to the networkinterface device when the threshold level is exceeded.
 23. The method ofclaim 22, further comprising: creating a window update commandcontaining the update information for the receive window, prior totransmitting the window update information.
 24. The method of claim 16,further comprising: transmitting a command from the application to thenetwork interface device; and piggybacking the update information forthe receive window on the command.
 25. The method of claim 16, furthercomprising transmitting a scatter/gather list for the application, fromthe computer to the network interface device, along with the updateinformation for the receive window.
 26. The method of claim 16, furthercomprising: receiving, by the network interface device from the network,at least one packet containing the data; processing a TCP header of thepacket by the network interface device; and storing data in the space inthe memory that corresponds to the TCP connection.
 27. The method ofclaim 16, further comprising: receiving, by the network interface devicefrom the network, at least one packet containing the data; processing aTCP header of the packet by the network interface device; and storingdata in a portion of the memory that is controlled by the application,including bypassing the space in the memory that corresponds to the TCPconnection.
 28. The method of claim 16, further comprising:accumulating, by the computer, a count of the data that has beenaccepted by the application from the space in the memory thatcorresponds to the TCP connection; and creating the update informationbased at least in part upon the count.
 29. A method for communicationbetween a computer having a memory, a network, and a network interfacedevice that is coupled between the computer and the network, the methodcomprising: receiving, by the network interface device, at least onepacket corresponding to a Transport Control Protocol (TCP) connection;forwarding a data portion of the packet from the network interfacedevice to a space in the memory corresponding to the TCP connection; andtransmitting a window update command corresponding to the TCP connectionfrom the computer to the network interface device to update a TCPreceive window of the network interface device.
 30. The method of claim29, further comprising: running an application corresponding to the TCPconnection on the computer; accepting the data by the application; andtransmitting a second window update command corresponding to the TCPconnection to update the TCP receive window with an indication that thedata was accepted by the application.
 31. The method of claim 29,further comprising TCP processing a TCP header of the packet by thenetwork interface device.
 32. The method of claim 29, furthercomprising: running an application on the computer, the applicationcorresponding to the TCP connection; and piggybacking the window updatecommand on another command being transmitted from the application to thenetwork interface device.
 34. The method of claim 29, furthercomprising: setting a threshold level of bytes to be consumed by theapplication; and transmitting the window update command from thecomputer to the network interface device when the threshold level isexceeded.
 35. A system for network communication, the system comprising:a computer; and a device coupled between the computer and a network toreceive from the network at least one packet associated with a TransportControl Protocol (TCP) connection, to process a TCP header for the atleast one packet and to send to the computer data from the at least onepacket, the computer having a memory, running an applicationcorresponding to the TCP connection and having instructions to transmitwindow information to the device to advertise to the network a receivewindow of space in the memory that corresponds to the TCP connection.36. The system of claim 35, wherein the instructions to transmit windowinformation include directions to send window update information inresponse to the data being accepted by the application.
 37. The systemof claim 35, wherein the instructions to transmit window informationinclude directions to create a window update command containing thewindow update information.
 38. The method of claim 35, wherein theinstructions to transmit window information include directions topiggyback the window information on other information that is beingtransmitted from the computer to the network interface device.
 39. Themethod of claim 35, wherein the instructions to transmit window updateinformation include directions to set a threshold level of bytes of datato be consumed by the application and directions to transmit the windowupdate information from the computer to the network interface devicewhen the threshold level is exceeded.
 40. The system of claim 35,wherein the instructions to transmit window information includedirections to create a window update command containing window updateinformation.
 41. The system of claim 35, wherein the computer furthercomprises instructions to transmit a command from the application to thenetwork interface device, and the instructions to transmit windowinformation include directions to piggyback window update information onthe command.
 42. The system of claim 35, wherein the computer furthercomprises instructions to transmit a scatter/gather list for theapplication, from the computer to the network interface device, alongwith the window information.
 43. The system of claim 35, wherein thedevice further comprises: a mechanism to store the data in the space inthe memory that corresponds to the TCP connection.
 44. The system ofclaim 35, wherein the device further comprises: a mechanism to store thedata in a portion of the memory that is controlled by the application,wherein the data is not stored in the space in the memory thatcorresponds to the TCP connection.
 45. The system of claim 35, whereinthe computer further comprises a mechanism to accumulate a count of thedata that has been accepted by the application from the space in thememory that corresponds to the TCP connection and to create the updateinformation based at least in part upon the count.